Skip to content

Commit c41e13f

Browse files
authored
Merge pull request #1032 from PHPCSStandards/phpcs-4.0/modernize/use-dirname-levels
Modernize: use `$levels` parameter for `dirname()`
2 parents 7a3c1e3 + 14913ed commit c41e13f

9 files changed

+9
-9
lines changed

src/Ruleset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ private function expandRulesetReference($ref, $rulesetDir, $depth=0)
10061006
if (is_file($ref) === true) {
10071007
if (substr($ref, -9) === 'Sniff.php') {
10081008
// A single external sniff.
1009-
$this->rulesetDirs[] = dirname(dirname(dirname($ref)));
1009+
$this->rulesetDirs[] = dirname($ref, 3);
10101010
return [$ref];
10111011
}
10121012
} else {

src/Util/Standards.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function getInstalledStandardPaths()
2727
{
2828
$ds = DIRECTORY_SEPARATOR;
2929

30-
$installedPaths = [dirname(dirname(__DIR__)).$ds.'src'.$ds.'Standards'];
30+
$installedPaths = [dirname(__DIR__, 2).$ds.'src'.$ds.'Standards'];
3131
$configPaths = Config::getConfigData('installed_paths');
3232
if ($configPaths !== null) {
3333
$installedPaths = array_merge($installedPaths, explode(',', $configPaths));

tests/Core/Filters/AbstractFilterTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected function getFilteredResultsAsArray(Filter $filter)
129129
*/
130130
protected static function getBaseDir()
131131
{
132-
return dirname(dirname(dirname(__DIR__)));
132+
return dirname(__DIR__, 3);
133133

134134
}//end getBaseDir()
135135

tests/Core/Ruleset/ConstructorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function testStandardsAreRegisteredWithAutoloader($cliArgs, $expected)
114114
*/
115115
public static function dataStandardsAreRegisteredWithAutoloader()
116116
{
117-
$basePath = dirname(dirname(dirname(__DIR__))).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR;
117+
$basePath = dirname(__DIR__, 3).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR;
118118
$defaultPaths = [
119119
$basePath.'PEAR' => 'PEAR',
120120
$basePath.'PSR1' => 'PSR1',

tests/Core/Ruleset/RegisterSniffsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static function setUpBeforeClass(): void
7878
ksort(self::$originalSniffs);
7979

8080
// Update the sniff file list.
81-
$standardsDir = dirname(dirname(dirname(__DIR__))).DIRECTORY_SEPARATOR;
81+
$standardsDir = dirname(__DIR__, 3).DIRECTORY_SEPARATOR;
8282
$standardsDir .= 'src'.DIRECTORY_SEPARATOR.'Standards'.DIRECTORY_SEPARATOR;
8383

8484
self::$psr1SniffAbsolutePaths = self::relativeToAbsoluteSniffFiles($standardsDir, self::$psr1SniffFiles);

tests/Core/Ruleset/RuleInclusionAbsoluteLinuxTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ final class RuleInclusionAbsoluteLinuxTest extends TestCase
5151
protected function setUp(): void
5252
{
5353
$this->standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml';
54-
$repoRootDir = dirname(dirname(dirname(__DIR__)));
54+
$repoRootDir = dirname(__DIR__, 3);
5555

5656
// On-the-fly adjust the ruleset test file to be able to test sniffs included with absolute paths.
5757
$contents = file_get_contents($this->standard);

tests/Core/Ruleset/RuleInclusionAbsoluteWindowsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final class RuleInclusionAbsoluteWindowsTest extends TestCase
5353
protected function setUp(): void
5454
{
5555
$this->standard = __DIR__.'/'.basename(__FILE__, '.php').'.xml';
56-
$repoRootDir = dirname(dirname(dirname(__DIR__)));
56+
$repoRootDir = dirname(__DIR__, 3);
5757

5858
// On-the-fly adjust the ruleset test file to be able to test sniffs included with absolute paths.
5959
$contents = file_get_contents($this->standard);

tests/Core/Ruleset/RuleInclusionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ protected function setUp(): void
5959
$contents = file_get_contents($standard);
6060
self::$contents = $contents;
6161

62-
$repoRootDir = basename(dirname(dirname(dirname(__DIR__))));
62+
$repoRootDir = basename(dirname(__DIR__, 3));
6363

6464
$newPath = $repoRootDir;
6565
if (DIRECTORY_SEPARATOR === '\\') {

tests/Core/Standards/StandardRulesetsQATest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function dataBuildInStandards()
6363
{
6464
// Get a list of all build-in, PHPCS native standards.
6565
$sep = DIRECTORY_SEPARATOR;
66-
$targetDir = dirname(dirname(dirname(__DIR__))).$sep.'src'.$sep.'Standards'.$sep;
66+
$targetDir = dirname(__DIR__, 3).$sep.'src'.$sep.'Standards'.$sep;
6767
$rulesetFiles = glob($targetDir.'*'.$sep.'ruleset.xml');
6868

6969
$data = [];

0 commit comments

Comments
 (0)