@@ -232,7 +232,13 @@ public function process($files, $standard, array $sniffs=array(), $local=false)
232
232
throw new PHP_CodeSniffer_Exception ('$standard must be a string ' );
233
233
}
234
234
235
- $ this ->standardDir = realpath (dirname (__FILE__ ).'/CodeSniffer/Standards/ ' .$ standard );
235
+ if (is_dir ($ standard ) === true ) {
236
+ // This is a custom standard.
237
+ $ this ->standardDir = $ standard ;
238
+ $ standard = basename ($ standard );
239
+ } else {
240
+ $ this ->standardDir = realpath (dirname (__FILE__ ).'/CodeSniffer/Standards/ ' .$ standard );
241
+ }
236
242
237
243
// Reset the members.
238
244
$ this ->listeners = array ();
@@ -373,10 +379,18 @@ public static function getSniffFiles($dir, $standard=null)
373
379
374
380
$ included = $ standardClass ->getIncludedSniffs ();
375
381
foreach ($ included as $ sniff ) {
376
- $ sniffDir = realpath (dirname (__FILE__ )."/CodeSniffer/Standards/ $ sniff " );
377
-
378
- if ($ sniffDir === false ) {
379
- throw new PHP_CodeSniffer_Exception ("Included sniff $ sniff does not exist " );
382
+ if (is_dir ($ sniff ) === true ) {
383
+ // Trying to include from a custom standard.
384
+ $ sniffDir = $ sniff ;
385
+ $ sniff = basename ($ sniff );
386
+ } else if (is_file ($ sniff ) === true ) {
387
+ // Trying to include a custom sniff.
388
+ $ sniffDir = $ sniff ;
389
+ } else {
390
+ $ sniffDir = realpath (dirname (__FILE__ )."/CodeSniffer/Standards/ $ sniff " );
391
+ if ($ sniffDir === false ) {
392
+ throw new PHP_CodeSniffer_Exception ("Included sniff $ sniff does not exist " );
393
+ }
380
394
}
381
395
382
396
if (is_dir ($ sniffDir ) === true ) {
@@ -398,10 +412,18 @@ public static function getSniffFiles($dir, $standard=null)
398
412
399
413
$ excluded = $ standardClass ->getExcludedSniffs ();
400
414
foreach ($ excluded as $ sniff ) {
401
- $ sniffDir = realpath (dirname (__FILE__ )."/CodeSniffer/Standards/ $ sniff " );
402
-
403
- if ($ sniffDir === false ) {
404
- throw new PHP_CodeSniffer_Exception ("Excluded sniff $ sniff does not exist " );
415
+ if (is_dir ($ sniff ) === true ) {
416
+ // Trying to exclude from a custom standard.
417
+ $ sniffDir = $ sniff ;
418
+ $ sniff = basename ($ sniff );
419
+ } else if (is_file ($ sniff ) === true ) {
420
+ // Trying to exclude a custom sniff.
421
+ $ sniffDir = $ sniff ;
422
+ } else {
423
+ $ sniffDir = realpath (dirname (__FILE__ )."/CodeSniffer/Standards/ $ sniff " );
424
+ if ($ sniffDir === false ) {
425
+ throw new PHP_CodeSniffer_Exception ("Excluded sniff $ sniff does not exist " );
426
+ }
405
427
}
406
428
407
429
if (is_dir ($ sniffDir ) === true ) {
@@ -1410,7 +1432,14 @@ public static function isInstalledStandard($standard)
1410
1432
{
1411
1433
$ standardDir = dirname (__FILE__ );
1412
1434
$ standardDir .= '/CodeSniffer/Standards/ ' .$ standard ;
1413
- return (is_file ("$ standardDir/ {$ standard }CodingStandard.php " ) === true );
1435
+ if (is_file ("$ standardDir/ {$ standard }CodingStandard.php " ) === true ) {
1436
+ return true ;
1437
+ } else {
1438
+ // This could be a custom standard, installed outside our
1439
+ // standards directory.
1440
+ $ standardFile = rtrim ($ standard , ' / \\' ).DIRECTORY_SEPARATOR .basename ($ standard ).'CodingStandard.php ' ;
1441
+ return (is_file ($ standardFile ) === true );
1442
+ }
1414
1443
1415
1444
}//end isInstalledStandard()
1416
1445
0 commit comments