Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- 'e2e/applied-rule-removed-node'
- 'e2e/parallel with space'
- 'e2e/wildcards-path-config'
- 'e2e/wildcards-path-import-config'

name: End to end test - ${{ matrix.directory }}

Expand Down
1 change: 1 addition & 0 deletions e2e/wildcards-path-import-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
7 changes: 7 additions & 0 deletions e2e/wildcards-path-import-config/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"require": {
"php": "^8.1"
},
"minimum-stability": "dev",
"prefer-stable": true
}
10 changes: 10 additions & 0 deletions e2e/wildcards-path-import-config/config/import_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(RemoveEmptyClassMethodRector::class);
};
10 changes: 10 additions & 0 deletions e2e/wildcards-path-import-config/config/import_config_another.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(RemoveUnreachableStatementRector::class);
};
38 changes: 38 additions & 0 deletions e2e/wildcards-path-import-config/expected-output.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
2 files with changes
====================

1) src/GotUnreachableReturn.php:4

---------- begin diff ----------
@@ @@
public function run()
{
throw new Exception();
-
- return 'test';
}
}
----------- end diff -----------

Applied rules:
* RemoveUnreachableStatementRector


2) src/DeadConstructor.php:1

---------- begin diff ----------
@@ @@

final class DeadConstructor
{
- public function __construct()
- {
- }
}
----------- end diff -----------

Applied rules:
* RemoveEmptyClassMethodRector


[OK] 2 files would have changed (dry-run) by Rector
13 changes: 13 additions & 0 deletions e2e/wildcards-path-import-config/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src',
]);

$rectorConfig->import(__DIR__ . '/config/*');
};
8 changes: 8 additions & 0 deletions e2e/wildcards-path-import-config/src/DeadConstructor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

final class DeadConstructor
{
public function __construct()
{
}
}
11 changes: 11 additions & 0 deletions e2e/wildcards-path-import-config/src/GotUnreachableReturn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

final class GotUnreachableReturn
{
public function run()
{
throw new Exception();

return 'test';
}
}
15 changes: 14 additions & 1 deletion packages/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\FileSystem\FilesystemTweaker;
use Rector\Core\NodeAnalyzer\ScopeAnalyzer;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\PhpVersion;
Expand Down Expand Up @@ -198,7 +199,7 @@ static function (
}
}

public function import(string $filePath): void
private function importFile(string $filePath): void
{
Assert::fileExists($filePath);

Expand All @@ -210,6 +211,18 @@ public function import(string $filePath): void
$callable($self);
}

public function import(string $filePath): void
{
$paths = [$filePath];

$filesystemTweaker = new FilesystemTweaker();
$paths = $filesystemTweaker->resolveWithFnmatch($paths);

foreach ($paths as $path) {
$this->importFile($path);
}
}

/**
* @param array<class-string<RectorInterface>> $rectorClasses
*/
Expand Down