Skip to content

Commit 638d340

Browse files
committed
Revert "Improved support for including rulesets inside other rulesets using relative paths"
This reverts commit bc8c394. Code is being rewritten in 1.5.0 and this change may cause backwards compatibility issues for some rare cases.
1 parent 0b97dae commit 638d340

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

CodeSniffer.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ public function setTokenListeners($standard, array $sniffs=array())
608608

609609
if (basename($standard) === 'ruleset.xml') {
610610
// 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
612612
// the standardDir to be the directory, we will process both
613613
// the directory (for custom sniffs) and the ruleset.xml file
614614
// (as it uses the generic name) in getSniffFiles.
@@ -715,7 +715,7 @@ public function setTokenListeners($standard, array $sniffs=array())
715715
* Sniffs are found by recursing the standard directory and also by
716716
* asking the standard for included sniffs.
717717
*
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.
719719
* @param string $standard The name of the coding standard. If NULL, no
720720
* included sniffs will be checked for.
721721
*
@@ -758,9 +758,6 @@ public function getSniffFiles($dir, $standard=null)
758758
$rulesetPath = $dir;
759759
if (is_dir($rulesetPath) === true) {
760760
$rulesetPath .= '/ruleset.xml';
761-
$rulesetDir = $dir;
762-
} else {
763-
$rulesetDir = dirname($dir);
764761
}
765762

766763
$ruleset = simplexml_load_file($rulesetPath);
@@ -769,14 +766,14 @@ public function getSniffFiles($dir, $standard=null)
769766
}
770767

771768
foreach ($ruleset->rule as $rule) {
772-
$includedSniffs = array_merge($includedSniffs, $this->_expandRulesetReference($rule['ref'], $rulesetDir));
769+
$includedSniffs = array_merge($includedSniffs, $this->_expandRulesetReference($rule['ref']));
773770

774771
if (isset($rule->exclude) === true) {
775772
foreach ($rule->exclude as $exclude) {
776-
$excludedSniffs = array_merge($excludedSniffs, $this->_expandRulesetReference($exclude['name'], $rulesetDir));
773+
$excludedSniffs = array_merge($excludedSniffs, $this->_expandRulesetReference($exclude['name']));
777774
}
778775
}
779-
}
776+
}//end foreach
780777
}//end if
781778

782779
$includedSniffs = array_unique($includedSniffs);
@@ -801,13 +798,12 @@ public function getSniffFiles($dir, $standard=null)
801798
/**
802799
* Expand a ruleset sniff reference into a list of sniff files.
803800
*
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.
806802
*
807803
* @return array
808804
* @throws PHP_CodeSniffer_Exception If the sniff reference is invalid.
809805
*/
810-
private function _expandRulesetReference($sniff, $rulesetDir)
806+
private function _expandRulesetReference($sniff)
811807
{
812808
$referencedSniffs = array();
813809

@@ -822,7 +818,12 @@ private function _expandRulesetReference($sniff, $rulesetDir)
822818
// to absolute paths. If this fails, let the sniff path run through
823819
// the normal checks and have it fail as normal.
824820
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);
826827
if ($realpath !== false) {
827828
$sniff = $realpath;
828829
}
@@ -850,12 +851,12 @@ private function _expandRulesetReference($sniff, $rulesetDir)
850851

851852
$path = $parts[0].'/Sniffs/'.$parts[1].'/'.$parts[2].'Sniff.php';
852853
$path = realpath(dirname(__FILE__).'/CodeSniffer/Standards/'.$path);
853-
if ($path === false && $rulesetDir !== '') {
854+
if ($path === false && self::$standardDir !== '') {
854855
// The sniff is not locally installed, so check if it is being
855856
// referenced as a remote sniff outside the install. We do this by
856857
// looking directly in the passed standard dir to see if it is
857858
// 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');
859860
}
860861
}
861862
}//end if

package.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ http://pear.php.net/dtd/package-2.0.xsd">
4444
-- Thanks to Eloy Lafuente for the patch
4545
- Squiz LowercaseClassKeywordsSniff now checks for the TRAIT keyword
4646
-- Thanks to Anthon Pang for the patch
47-
- Improved support for including rulesets inside other rulesets using relative paths
4847
- If you create your own PHP_CodeSniffer object, PHPCS will no longer exit when an unknown argument is found
4948
-- This allows you to create wrapper scripts for PHPCS more easily
5049
- PSR2 MethodDeclarationSniff no longer generates a notice for methods named "_"

0 commit comments

Comments
 (0)