Skip to content
Closed
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
2 changes: 2 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@
$rectorConfig->reportingRealPath(false);

$rectorConfig->treatClassesAsFinal(false);

$rectorConfig->includePostRectorsInReports(false);
};
4 changes: 4 additions & 0 deletions e2e/applied-auto-import/expected-output.diff
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

Applied rules:
* RenameClassRector
* DocblockNameImportingPostRector
* NameImportingPostRector
* UnusedImportRemovingPostRector
* UseAddingPostRector


[OK] 1 file would have been changed (dry-run) by Rector
1 change: 1 addition & 0 deletions e2e/applied-auto-import/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

$rectorConfig->importNames();
$rectorConfig->removeUnusedImports();
$rectorConfig->includePostRectorsInReports(true);
};
5 changes: 5 additions & 0 deletions src/Config/RectorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,4 +451,9 @@ public function setOverflowLevels(array $levelOverflows): void
{
SimpleParameterProvider::addParameter(Option::LEVEL_OVERFLOWS, $levelOverflows);
}

public function includePostRectorsInReports(bool $includePostRectorsInReports = true): void
{
SimpleParameterProvider::setParameter(Option::INCLUDE_POST_RECTORS_IN_REPORTS, $includePostRectorsInReports);
}
}
5 changes: 5 additions & 0 deletions src/Configuration/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,9 @@ final class Option
* @var string
*/
public const KAIZEN = 'kaizen';

/**
* @var string
*/
public const INCLUDE_POST_RECTORS_IN_REPORTS = 'include_post_rectors_in_reports';
}
12 changes: 12 additions & 0 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ final class RectorConfigBuilder

private ?bool $isWithPhpLevelUsed = null;

private ?bool $includePostRectorsInReports = null;

/**
* @var array<class-string<SetProviderInterface>,bool>
*/
Expand Down Expand Up @@ -390,6 +392,10 @@ public function __invoke(RectorConfig $rectorConfig): void
if ($this->levelOverflows !== []) {
$rectorConfig->setOverflowLevels($this->levelOverflows);
}

if ($this->includePostRectorsInReports !== null) {
$rectorConfig->includePostRectorsInReports($this->includePostRectorsInReports);
}
}

/**
Expand Down Expand Up @@ -1291,4 +1297,10 @@ public function withSetProviders(string ...$setProviders): self

return $this;
}

public function withIncludePostRectorsInReports(bool $includePostRectorsInReports = true): self
{
$this->includePostRectorsInReports = $includePostRectorsInReports;
return $this;
}
}
5 changes: 3 additions & 2 deletions src/Testing/PHPUnit/ValueObject/RectorTestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\Testing\PHPUnit\ValueObject;

use Rector\Contract\Rector\RectorInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Rector\Util\RectorClassesSorter;
use Rector\ValueObject\ProcessResult;

Expand All @@ -25,7 +26,7 @@ public function getChangedContents(): string
}

/**
* @return array<class-string<RectorInterface>>
* @return array<class-string<RectorInterface|PostRectorInterface>>
*/
public function getAppliedRectorClasses(): array
{
Expand All @@ -35,6 +36,6 @@ public function getAppliedRectorClasses(): array
$rectorClasses = array_merge($rectorClasses, $fileDiff->getRectorClasses());
}

return RectorClassesSorter::sortAndFilterOutPostRectors($rectorClasses);
return RectorClassesSorter::sort($rectorClasses);
}
}
16 changes: 14 additions & 2 deletions src/Util/RectorClassesSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

namespace Rector\Util;

use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Contract\Rector\RectorInterface;
use Rector\PostRector\Contract\Rector\PostRectorInterface;

final class RectorClassesSorter
{
/**
* @param array<class-string<RectorInterface|PostRectorInterface>> $rectorClasses
* @return array<class-string<RectorInterface>>
* @return array<class-string<RectorInterface|PostRectorInterface>>
*/
public static function sortAndFilterOutPostRectors(array $rectorClasses): array
public static function sort(array $rectorClasses): array
{
$rectorClasses = array_unique($rectorClasses);

Expand All @@ -23,6 +25,16 @@ public static function sortAndFilterOutPostRectors(array $rectorClasses): array
);
sort($mainRectorClasses);

if (SimpleParameterProvider::provideBoolParameter(Option::INCLUDE_POST_RECTORS_IN_REPORTS)) {
$postRectorClasses = array_filter(
$rectorClasses,
fn (string $rectorClass): bool => is_a($rectorClass, PostRectorInterface::class, true)
);
sort($postRectorClasses);

return array_merge($mainRectorClasses, $postRectorClasses);
}

return $mainRectorClasses;
}
}
5 changes: 3 additions & 2 deletions src/ValueObject/Reporting/FileDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Contract\Rector\RectorInterface;
use Rector\Parallel\ValueObject\BridgeItem;
use Rector\PostRector\Contract\Rector\PostRectorInterface;
use Rector\Util\RectorClassesSorter;
use Symplify\EasyParallel\Contract\SerializableInterface;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -82,7 +83,7 @@ public function getRectorShortClasses(): array
}

/**
* @return array<class-string<RectorInterface>>
* @return array<class-string<RectorInterface|PostRectorInterface>>
*/
public function getRectorClasses(): array
{
Expand All @@ -92,7 +93,7 @@ public function getRectorClasses(): array
$rectorClasses[] = $rectorWithLineChange->getRectorClass();
}

return RectorClassesSorter::sortAndFilterOutPostRectors($rectorClasses);
return RectorClassesSorter::sort($rectorClasses);
}

public function getFirstLineNumber(): ?int
Expand Down
Loading