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 @@ -33,6 +33,7 @@ jobs:
- 'e2e/parallel with space'
- 'e2e/wildcards-path-config'
- 'e2e/wildcards-path-import-config'
- 'e2e/different-path-over-skip-config'

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

Expand Down
1 change: 1 addition & 0 deletions e2e/different-path-over-skip-config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
7 changes: 7 additions & 0 deletions e2e/different-path-over-skip-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
}
21 changes: 21 additions & 0 deletions e2e/different-path-over-skip-config/expected-output.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1 file with changes
===================

1) src/models/DeadConstructor.php:3

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

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

Applied rules:
* RemoveEmptyClassMethodRector


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

declare(strict_types=1);

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

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

$rectorConfig->skip([
RemoveEmptyClassMethodRector::class => [
__DIR__ . '/src/controllers',
],
]);

$rectorConfig->rule(RemoveEmptyClassMethodRector::class);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace controllers;

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

namespace model;

final class DeadConstructor
{
public function __construct()
{
}
}
6 changes: 3 additions & 3 deletions packages-tests/Skipper/Skipper/SkipperRectorRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function testRemovingServiceFromContainer(): void
// register 2 rules, but one is skipped
$this->bootFromConfigFiles([__DIR__ . '/config/single_skipped_rule_config.php']);

$container = self::getContainer();
$rectorConfig = self::getContainer();

// to invoke before resolving
$container->make(FileNodesFetcher::class);
$rectorConfig->make(FileNodesFetcher::class);

// here 1 rule should be removed and 1 should remain
/** @var RewindableGenerator<int, RectorInterface> $rectorsIterator */
$rectorsIterator = $container->tagged(RectorInterface::class);
$rectorsIterator = $rectorConfig->tagged(RectorInterface::class);
$this->assertCount(1, $rectorsIterator);

$rectors = iterator_to_array($rectorsIterator->getIterator());
Expand Down
9 changes: 6 additions & 3 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,12 @@ static function (
}

$skippedClassResolver = new SkippedClassResolver();
$skippedClasses = array_keys($skippedClassResolver->resolve());
foreach ($skippedClasses as $skippedClass) {
ContainerMemento::forgetService($container, $skippedClass);
$skippedElements = $skippedClassResolver->resolve();
foreach ($skippedElements as $skippedClass => $path) {
// completely forget the Rector rule only when no path specified
if ($path === null) {
ContainerMemento::forgetService($container, $skippedClass);
Copy link
Copy Markdown
Contributor

@staabm staabm Aug 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you give me an idea why we need to drop classes from the container when rules are skipped?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}

$hasForgotten = true;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this flag still correct then?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems used on line 727 to run once on phpunit

Expand Down