Skip to content

Commit 266c167

Browse files
committed
Added earlier guard code for sniff files that are not in the correct directory structure (ref #628)
1 parent de78f99 commit 266c167

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

CodeSniffer.php

+6
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,7 @@ private function _shouldProcessElement($element, $depth=0)
12851285
* listeners to.
12861286
*
12871287
* @return void
1288+
* @throws PHP_CodeSniffer_Exception If a sniff file path is invalid.
12881289
*/
12891290
public function registerSniffs($files, $restrictions)
12901291
{
@@ -1304,6 +1305,11 @@ public function registerSniffs($files, $restrictions)
13041305
}
13051306

13061307
$className = substr($file, ($slashPos + 1));
1308+
1309+
if (substr_count($className, DIRECTORY_SEPARATOR) !== 3) {
1310+
throw new PHP_CodeSniffer_Exception("Sniff file $className is not valid; sniff files must be located in a .../StandardName/Sniffs/CategoryName/ directory");
1311+
}
1312+
13071313
$className = substr($className, 0, -4);
13081314
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
13091315

0 commit comments

Comments
 (0)