@@ -608,7 +608,7 @@ public function setTokenListeners($standard, array $sniffs=array())
608
608
609
609
if (basename ($ standard ) === 'ruleset.xml ' ) {
610
610
// The ruleset uses the generic name, so this may actually
611
- // be a complete standard with it's own sniffs. By setting
611
+ // be a complete standard with it's own sniffs. By setting the
612
612
// the standardDir to be the directory, we will process both
613
613
// the directory (for custom sniffs) and the ruleset.xml file
614
614
// (as it uses the generic name) in getSniffFiles.
@@ -715,7 +715,7 @@ public function setTokenListeners($standard, array $sniffs=array())
715
715
* Sniffs are found by recursing the standard directory and also by
716
716
* asking the standard for included sniffs.
717
717
*
718
- * @param string $dir The directory in which to look for the files.
718
+ * @param string $dir The directory where to look for the files.
719
719
* @param string $standard The name of the coding standard. If NULL, no
720
720
* included sniffs will be checked for.
721
721
*
@@ -758,9 +758,6 @@ public function getSniffFiles($dir, $standard=null)
758
758
$ rulesetPath = $ dir ;
759
759
if (is_dir ($ rulesetPath ) === true ) {
760
760
$ rulesetPath .= '/ruleset.xml ' ;
761
- $ rulesetDir = $ dir ;
762
- } else {
763
- $ rulesetDir = dirname ($ dir );
764
761
}
765
762
766
763
$ ruleset = simplexml_load_file ($ rulesetPath );
@@ -769,14 +766,14 @@ public function getSniffFiles($dir, $standard=null)
769
766
}
770
767
771
768
foreach ($ ruleset ->rule as $ rule ) {
772
- $ includedSniffs = array_merge ($ includedSniffs , $ this ->_expandRulesetReference ($ rule ['ref ' ], $ rulesetDir ));
769
+ $ includedSniffs = array_merge ($ includedSniffs , $ this ->_expandRulesetReference ($ rule ['ref ' ]));
773
770
774
771
if (isset ($ rule ->exclude ) === true ) {
775
772
foreach ($ rule ->exclude as $ exclude ) {
776
- $ excludedSniffs = array_merge ($ excludedSniffs , $ this ->_expandRulesetReference ($ exclude ['name ' ], $ rulesetDir ));
773
+ $ excludedSniffs = array_merge ($ excludedSniffs , $ this ->_expandRulesetReference ($ exclude ['name ' ]));
777
774
}
778
775
}
779
- }
776
+ }//end foreach
780
777
}//end if
781
778
782
779
$ includedSniffs = array_unique ($ includedSniffs );
@@ -801,13 +798,12 @@ public function getSniffFiles($dir, $standard=null)
801
798
/**
802
799
* Expand a ruleset sniff reference into a list of sniff files.
803
800
*
804
- * @param string $sniff The sniff reference from the ruleset.xml file.
805
- * @param string $rulesetDir The directory of the ruleset.xml file.
801
+ * @param string $sniff The sniff reference from the rulset.xml file.
806
802
*
807
803
* @return array
808
804
* @throws PHP_CodeSniffer_Exception If the sniff reference is invalid.
809
805
*/
810
- private function _expandRulesetReference ($ sniff, $ rulesetDir )
806
+ private function _expandRulesetReference ($ sniff )
811
807
{
812
808
$ referencedSniffs = array ();
813
809
@@ -822,7 +818,12 @@ private function _expandRulesetReference($sniff, $rulesetDir)
822
818
// to absolute paths. If this fails, let the sniff path run through
823
819
// the normal checks and have it fail as normal.
824
820
if (substr ($ sniff , 0 , 1 ) === '. ' ) {
825
- $ realpath = realpath ($ rulesetDir .'/ ' .$ sniff );
821
+ $ standardDir = self ::$ standardDir ;
822
+ if (substr (self ::$ standardDir , -4 ) === '.xml ' ) {
823
+ $ standardDir = dirname ($ standardDir );
824
+ }
825
+
826
+ $ realpath = realpath ($ standardDir .'/ ' .$ sniff );
826
827
if ($ realpath !== false ) {
827
828
$ sniff = $ realpath ;
828
829
}
@@ -850,12 +851,12 @@ private function _expandRulesetReference($sniff, $rulesetDir)
850
851
851
852
$ path = $ parts [0 ].'/Sniffs/ ' .$ parts [1 ].'/ ' .$ parts [2 ].'Sniff.php ' ;
852
853
$ path = realpath (dirname (__FILE__ ).'/CodeSniffer/Standards/ ' .$ path );
853
- if ($ path === false && $ rulesetDir !== '' ) {
854
+ if ($ path === false && self :: $ standardDir !== '' ) {
854
855
// The sniff is not locally installed, so check if it is being
855
856
// referenced as a remote sniff outside the install. We do this by
856
857
// looking directly in the passed standard dir to see if it is
857
858
// installed in there.
858
- $ path = realpath ($ rulesetDir .'/Sniffs/ ' .$ parts [1 ].'/ ' .$ parts [2 ].'Sniff.php ' );
859
+ $ path = realpath (self :: $ standardDir .'/Sniffs/ ' .$ parts [1 ].'/ ' .$ parts [2 ].'Sniff.php ' );
859
860
}
860
861
}
861
862
}//end if
0 commit comments