Skip to content

Commit c862026

Browse files
committed
Instead of assuming sniffs are located in our own coding standard dir, we now determine the correct coding standard namw and sniff classname from the file path. This allows external sniffs to have their own Sniffs dir.
git-svn-id: http://svn.php.net/repository/pear/packages/PHP_CodeSniffer/trunk@248543 c90b9560-bf6c-de11-be94-00142212c4b1
1 parent 170d620 commit c862026

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

CodeSniffer.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,16 +296,16 @@ protected function registerTokenListeners($standard, array $sniffs=array())
296296
}
297297
}
298298

299-
$csPath = dirname(__FILE__).DIRECTORY_SEPARATOR.'CodeSniffer'.DIRECTORY_SEPARATOR;
300-
301299
foreach ($files as $file) {
302300

303-
if (strpos($file, $csPath) === false) {
304-
continue;
305-
}
301+
// Work out where the position of /StandardName/Sniffs/... is
302+
// so we can determine what the class will be called.
303+
$sniffPos = strrpos($file, DIRECTORY_SEPARATOR.'Sniffs'.DIRECTORY_SEPARATOR);
304+
if ($sniffPos === false) continue;
305+
$slashPos = strrpos(substr($file, 0, $sniffPos), DIRECTORY_SEPARATOR);
306+
if ($slashPos === false) continue;
306307

307-
$className = substr($file, strpos($file, $csPath));
308-
$className = substr($className, (strlen($csPath) + 10));
308+
$className = substr($file, ($slashPos + 1));
309309
$className = substr($className, 0, -4);
310310
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
311311

0 commit comments

Comments
 (0)