diff --git a/src/Ruleset.php b/src/Ruleset.php index c9a89d0c9d..0b72594455 100644 --- a/src/Ruleset.php +++ b/src/Ruleset.php @@ -1006,7 +1006,7 @@ private function expandRulesetReference($ref, $rulesetDir, $depth=0) if (is_file($ref) === true) { if (substr($ref, -9) === 'Sniff.php') { // A single external sniff. - $this->rulesetDirs[] = dirname(dirname(dirname($ref))); + $this->rulesetDirs[] = dirname($ref, 3); return [$ref]; } } else { diff --git a/src/Util/Standards.php b/src/Util/Standards.php index 527f5b792d..ebee5c49b0 100644 --- a/src/Util/Standards.php +++ b/src/Util/Standards.php @@ -27,7 +27,7 @@ public static function getInstalledStandardPaths() { $ds = DIRECTORY_SEPARATOR; - $installedPaths = [dirname(dirname(__DIR__)).$ds.'src'.$ds.'Standards']; + $installedPaths = [dirname(__DIR__, 2).$ds.'src'.$ds.'Standards']; $configPaths = Config::getConfigData('installed_paths'); if ($configPaths !== null) { $installedPaths = array_merge($installedPaths, explode(',', $configPaths)); diff --git a/tests/Core/Filters/AbstractFilterTestCase.php b/tests/Core/Filters/AbstractFilterTestCase.php index f95a51c0c7..1c656cc23f 100644 --- a/tests/Core/Filters/AbstractFilterTestCase.php +++ b/tests/Core/Filters/AbstractFilterTestCase.php @@ -129,7 +129,7 @@ protected function getFilteredResultsAsArray(Filter $filter) */ protected static function getBaseDir() { - return dirname(dirname(dirname(__DIR__))); + return dirname(__DIR__, 3); }//end getBaseDir() diff --git a/tests/Core/Ruleset/ConstructorTest.php b/tests/Core/Ruleset/ConstructorTest.php index 3700edd7fd..4880f9112e 100644 --- a/tests/Core/Ruleset/ConstructorTest.php +++ b/tests/Core/Ruleset/ConstructorTest.php @@ -114,7 +114,7 @@ public function testStandardsAreRegisteredWithAutoloader($cliArgs, $expected) */ public static function dataStandardsAreRegisteredWithAutoloader() { - $basePath = dirname(dirname(dirname(__DIR__))).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR; + $basePath = dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR; $defaultPaths = [ $basePath.'PEAR' => 'PEAR', $basePath.'PSR1' => 'PSR1', diff --git a/tests/Core/Ruleset/RegisterSniffsTest.php b/tests/Core/Ruleset/RegisterSniffsTest.php index d9510e18b2..8c4afabc95 100644 --- a/tests/Core/Ruleset/RegisterSniffsTest.php +++ b/tests/Core/Ruleset/RegisterSniffsTest.php @@ -78,7 +78,7 @@ public static function setUpBeforeClass(): void ksort(self::$originalSniffs); // Update the sniff file list. - $standardsDir = dirname(dirname(dirname(__DIR__))).DIRECTORY_SEPARATOR; + $standardsDir = dirname(__DIR__, 3).DIRECTORY_SEPARATOR; $standardsDir .= 'src'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR; self::$psr1SniffAbsolutePaths = self::relativeToAbsoluteSniffFiles($standardsDir, self::$psr1SniffFiles); diff --git a/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php b/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php index 80eb4b7ae9..ecad3205f0 100644 --- a/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php +++ b/tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php @@ -51,7 +51,7 @@ final class RuleInclusionAbsoluteLinuxTest extends TestCase protected function setUp(): void { $this->standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml'; - $repoRootDir = dirname(dirname(dirname(__DIR__))); + $repoRootDir = dirname(__DIR__, 3); // On-the-fly adjust the ruleset test file to be able to test sniffs included with absolute paths. $contents = file_get_contents($this->standard); diff --git a/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php b/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php index 73647cad0c..53edcb6747 100644 --- a/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php +++ b/tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php @@ -53,7 +53,7 @@ final class RuleInclusionAbsoluteWindowsTest extends TestCase protected function setUp(): void { $this->standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml'; - $repoRootDir = dirname(dirname(dirname(__DIR__))); + $repoRootDir = dirname(__DIR__, 3); // On-the-fly adjust the ruleset test file to be able to test sniffs included with absolute paths. $contents = file_get_contents($this->standard); diff --git a/tests/Core/Ruleset/RuleInclusionTest.php b/tests/Core/Ruleset/RuleInclusionTest.php index 9c31d1b79a..70a1547236 100644 --- a/tests/Core/Ruleset/RuleInclusionTest.php +++ b/tests/Core/Ruleset/RuleInclusionTest.php @@ -59,7 +59,7 @@ protected function setUp(): void $contents = file_get_contents($standard); self::$contents = $contents; - $repoRootDir = basename(dirname(dirname(dirname(__DIR__)))); + $repoRootDir = basename(dirname(__DIR__, 3)); $newPath = $repoRootDir; if (DIRECTORY_SEPARATOR === '\\') { diff --git a/tests/Core/Standards/StandardRulesetsQATest.php b/tests/Core/Standards/StandardRulesetsQATest.php index baba457437..73b113aa83 100644 --- a/tests/Core/Standards/StandardRulesetsQATest.php +++ b/tests/Core/Standards/StandardRulesetsQATest.php @@ -63,7 +63,7 @@ public static function dataBuildInStandards() { // Get a list of all build-in, PHPCS native standards. $sep = DIRECTORY_SEPARATOR; - $targetDir = dirname(dirname(dirname(__DIR__))).$sep.'src'.$sep.'Standards'.$sep; + $targetDir = dirname(__DIR__, 3).$sep.'src'.$sep.'Standards'.$sep; $rulesetFiles = glob($targetDir.'*'.$sep.'ruleset.xml'); $data = [];