Skip to content

Commit ec00329

Browse files
committed
Added test directory check
1 parent 6e31479 commit ec00329

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/Fixer/MultiOrderedClassElementsFixer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@
2020

2121
class MultiOrderedClassElementsFixer implements FixerInterface
2222
{
23+
private string $testPath;
2324
private OrderedClassElementsFixer $srcFixer;
2425
private OrderedClassElementsFixer $testFixer;
2526

2627
/**
27-
* @param array $srcOrder
28-
* @param array $testOrder
28+
* @param string $testPath
29+
* @param array $srcOrder
30+
* @param array $testOrder
2931
*/
30-
public function __construct(array $srcOrder, array $testOrder)
32+
public function __construct(string $testPath, array $srcOrder, array $testOrder)
3133
{
34+
$this->testPath = $testPath;
3235
$this->srcFixer = new OrderedClassElementsFixer();
3336
$this->testFixer = new OrderedClassElementsFixer();
3437

@@ -58,7 +61,7 @@ public function isRisky(): bool
5861

5962
public function fix(SplFileInfo $file, Tokens $tokens): void
6063
{
61-
$this->isTestClass($tokens)
64+
strpos($file->getPathname(), $this->testPath) === 0 && $this->isTestClass($tokens)
6265
? $this->testFixer->fix($file, $tokens)
6366
: $this->srcFixer->fix($file, $tokens);
6467
}

src/FixerFactory.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ final class FixerFactory
7676
public static function createFor(string $launchFile): Config
7777
{
7878
$workingDir = dirname($launchFile);
79+
$testsPath = $workingDir . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR;
7980

8081
self::setHeaderFrom($launchFile);
8182

@@ -114,9 +115,8 @@ public static function createFor(string $launchFile): Config
114115
self::$rules['Polymorphine/declare_strict_first_line'] = true;
115116
self::$rules['Polymorphine/brace_after_multiline_param_method'] = true;
116117

117-
$excludeSamples = function (SplFileInfo $file) use ($workingDir) {
118+
$excludeSamples = function (SplFileInfo $file) use ($testsPath) {
118119
$filePath = $file->getPath();
119-
$testsPath = $workingDir . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR;
120120
$samplesDir = DIRECTORY_SEPARATOR . 'code-samples' . DIRECTORY_SEPARATOR;
121121
return strpos($filePath, $testsPath) !== 0 || strpos($filePath, $samplesDir) === false;
122122
};
@@ -130,7 +130,7 @@ public static function createFor(string $launchFile): Config
130130
->registerCustomFixers([
131131
new Fixer\DoubleLineBeforeClassDefinitionFixer(),
132132
new Fixer\NoTrailingCommaInMultilineArrayFixer(),
133-
new Fixer\MultiOrderedClassElementsFixer($srcOrder, $testOrder),
133+
new Fixer\MultiOrderedClassElementsFixer($testsPath, $srcOrder, $testOrder),
134134
new Fixer\NamedConstructorsFirstStaticFixer(),
135135
new Fixer\AlignedMethodChainFixer(),
136136
new Fixer\AlignedAssignmentsFixer(),

tests/Fixer/MultiOrderedClassElementsFixerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ protected function fixer(): FixerInterface
184184
'method_private', 'method_private_static'
185185
];
186186

187-
return new MultiOrderedClassElementsFixer($srcOrder, $testOrder);
187+
return new MultiOrderedClassElementsFixer(dirname(__DIR__, 2), $srcOrder, $testOrder);
188188
}
189189

190190
protected function properties(): array

0 commit comments

Comments
 (0)