Skip to content

Commit 2c3da2b

Browse files
committed
Updated Rector to commit 1a19a3450852b3e048689560e8ddc95d12e28863
rectorphp/rector-src@1a19a34 [Diffs] Handle --no-diffs usage to show file have been changed if any with --dry-run + --no-diffs (#7619)
1 parent 454fbd3 commit 2c3da2b

File tree

10 files changed

+51
-13
lines changed

10 files changed

+51
-13
lines changed

src/Application/ApplicationFileProcessor.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function run(Configuration $configuration, InputInterface $input): Proces
9595
$filePaths = $this->filesFinder->findFilesInPaths($configuration->getPaths(), $configuration);
9696
// no files found
9797
if ($filePaths === []) {
98-
return new ProcessResult([], []);
98+
return new ProcessResult([], [], 0);
9999
}
100100
$this->missConfigurationReporter->reportVendorInPaths($filePaths);
101101
$this->missConfigurationReporter->reportStartWithShortOpenTag();
@@ -142,6 +142,7 @@ public function processFiles(array $filePaths, Configuration $configuration, ?ca
142142
$systemErrors = [];
143143
/** @var FileDiff[] $fileDiffs */
144144
$fileDiffs = [];
145+
$totalChanged = 0;
145146
foreach ($filePaths as $filePath) {
146147
if ($preFileCallback !== null) {
147148
$preFileCallback($filePath);
@@ -158,6 +159,9 @@ public function processFiles(array $filePaths, Configuration $configuration, ?ca
158159
if (is_callable($postFileCallback)) {
159160
$postFileCallback(1);
160161
}
162+
if ($fileProcessResult->hasChanged()) {
163+
++$totalChanged;
164+
}
161165
} catch (Throwable $throwable) {
162166
$this->changedFilesDetector->invalidateFile($filePath);
163167
if (StaticPHPUnitEnvironment::isPHPUnitRun()) {
@@ -166,7 +170,7 @@ public function processFiles(array $filePaths, Configuration $configuration, ?ca
166170
$systemErrors[] = $this->resolveSystemError($throwable, $filePath);
167171
}
168172
}
169-
return new ProcessResult($systemErrors, $fileDiffs);
173+
return new ProcessResult($systemErrors, $fileDiffs, $totalChanged);
170174
}
171175
private function processFile(File $file, Configuration $configuration): FileProcessResult
172176
{

src/Application/FileProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function processFile(File $file, Configuration $configuration): FileProce
8585
$parsingSystemError = $this->parseFileAndDecorateNodes($file);
8686
if ($parsingSystemError instanceof SystemError) {
8787
// we cannot process this file as the parsing and type resolving itself went wrong
88-
return new FileProcessResult([$parsingSystemError], null);
88+
return new FileProcessResult([$parsingSystemError], null, \false);
8989
}
9090
$fileHasChanged = \false;
9191
$filePath = $file->getFilePath();
@@ -119,7 +119,7 @@ public function processFile(File $file, Configuration $configuration): FileProce
119119
$currentFileDiff = $this->fileDiffFactory->createFileDiffWithLineChanges($configuration->shouldShowDiffs(), $file, $file->getOriginalFileContent(), $file->getFileContent(), $file->getRectorWithLineChanges());
120120
$file->setFileDiff($currentFileDiff);
121121
}
122-
return new FileProcessResult([], $file->getFileDiff());
122+
return new FileProcessResult([], $file->getFileDiff(), $file->hasChanged());
123123
}
124124
private function parseFileAndDecorateNodes(File $file): ?SystemError
125125
{

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '732ca2a054ea8ded3f79c04f90047f6841e730ac';
22+
public const PACKAGE_VERSION = '1a19a3450852b3e048689560e8ddc95d12e28863';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-11-11 10:36:29';
27+
public const RELEASE_DATE = '2025-11-11 12:22:54';
2828
/**
2929
* @var int
3030
*/

src/ChangesReporting/Output/ConsoleOutputFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private function normalizePathsToRelativeWithLine(string $errorMessage): string
109109
}
110110
private function createSuccessMessage(ProcessResult $processResult, Configuration $configuration): string
111111
{
112-
$changeCount = count($processResult->getFileDiffs());
112+
$changeCount = $processResult->getTotalChanged();
113113
if ($changeCount === 0) {
114114
return 'Rector is done!';
115115
}

src/Console/Command/ProcessCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ private function resolveReturnCode(ProcessResult $processResult, Configuration $
213213
if ($processResult->getFileDiffs() !== []) {
214214
return ExitCode::CHANGED_CODE;
215215
}
216+
if ($processResult->getTotalChanged() > 0) {
217+
return ExitCode::CHANGED_CODE;
218+
}
216219
return ExitCode::SUCCESS;
217220
}
218221
private function reportLoadedComposerBasedSets(): void

src/Console/Command/WorkerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function runWorker(Encoder $encoder, Decoder $decoder, Configuration $co
129129
/**
130130
* this invokes all listeners listening $decoder->on(...) @see \Symplify\EasyParallel\Enum\ReactEvent::DATA
131131
*/
132-
$encoder->write([ReactCommand::ACTION => Action::RESULT, self::RESULT => [Bridge::FILE_DIFFS => $processResult->getFileDiffs(), Bridge::FILES_COUNT => count($filePaths), Bridge::SYSTEM_ERRORS => $processResult->getSystemErrors(), Bridge::SYSTEM_ERRORS_COUNT => count($processResult->getSystemErrors())]]);
132+
$encoder->write([ReactCommand::ACTION => Action::RESULT, self::RESULT => [Bridge::FILE_DIFFS => $processResult->getFileDiffs(), Bridge::FILES_COUNT => count($filePaths), Bridge::SYSTEM_ERRORS => $processResult->getSystemErrors(), Bridge::SYSTEM_ERRORS_COUNT => count($processResult->getSystemErrors()), Bridge::TOTAL_CHANGED => $processResult->getTotalChanged()]]);
133133
});
134134
$decoder->on(ReactEvent::ERROR, $handleErrorCallback);
135135
}

src/Parallel/Application/ParallelFileProcessor.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function process(Schedule $schedule, string $mainScript, callable $postFi
9999
$serverPort = parse_url($serverAddress, \PHP_URL_PORT);
100100
$systemErrorsCount = 0;
101101
$reachedSystemErrorsCountLimit = \false;
102+
$totalChanged = 0;
102103
$handleErrorCallable = function (Throwable $throwable) use (&$systemErrors, &$systemErrorsCount, &$reachedSystemErrorsCountLimit): void {
103104
$systemErrors[] = new SystemError($throwable->getMessage(), $throwable->getFile(), $throwable->getLine());
104105
++$systemErrorsCount;
@@ -111,14 +112,22 @@ public function process(Schedule $schedule, string $mainScript, callable $postFi
111112
};
112113
$timeoutInSeconds = SimpleParameterProvider::provideIntParameter(Option::PARALLEL_JOB_TIMEOUT_IN_SECONDS);
113114
$fileChunksBudgetPerProcess = [];
114-
$processSpawner = function () use (&$systemErrors, &$fileDiffs, &$jobs, $postFileCallback, &$systemErrorsCount, &$reachedInternalErrorsCountLimit, $mainScript, $input, $serverPort, $streamSelectLoop, $timeoutInSeconds, $handleErrorCallable, &$fileChunksBudgetPerProcess, &$processSpawner): void {
115+
$processSpawner = function () use (&$systemErrors, &$fileDiffs, &$jobs, $postFileCallback, &$systemErrorsCount, &$reachedInternalErrorsCountLimit, $mainScript, $input, $serverPort, $streamSelectLoop, $timeoutInSeconds, $handleErrorCallable, &$fileChunksBudgetPerProcess, &$processSpawner, &$totalChanged): void {
115116
$processIdentifier = Random::generate();
116117
$workerCommandLine = $this->workerCommandLineFactory->create($mainScript, ProcessCommand::class, 'worker', $input, $processIdentifier, $serverPort);
117118
$fileChunksBudgetPerProcess[$processIdentifier] = self::MAX_CHUNKS_PER_WORKER;
118119
$parallelProcess = new ParallelProcess($workerCommandLine, $streamSelectLoop, $timeoutInSeconds);
119120
$parallelProcess->start(
120121
// 1. callable on data
121-
function (array $json) use ($parallelProcess, &$systemErrors, &$fileDiffs, &$jobs, $postFileCallback, &$systemErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier, &$fileChunksBudgetPerProcess, &$processSpawner): void {
122+
function (array $json) use ($parallelProcess, &$systemErrors, &$fileDiffs, &$jobs, $postFileCallback, &$systemErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier, &$fileChunksBudgetPerProcess, &$processSpawner, &$totalChanged): void {
123+
/** @var array{
124+
* total_changed: int,
125+
* system_errors: mixed[],
126+
* file_diffs: array<string, mixed>,
127+
* files_count: int,
128+
* system_errors_count: int
129+
* } $json */
130+
$totalChanged += $json[Bridge::TOTAL_CHANGED];
122131
// decode arrays to objects
123132
foreach ($json[Bridge::SYSTEM_ERRORS] as $jsonError) {
124133
if (is_string($jsonError)) {
@@ -177,6 +186,6 @@ function ($exitCode, string $stdErr) use (&$systemErrors, $processIdentifier): v
177186
if ($reachedSystemErrorsCountLimit) {
178187
$systemErrors[] = new SystemError(sprintf('Reached system errors count limit of %d, exiting...', self::SYSTEM_ERROR_LIMIT));
179188
}
180-
return new ProcessResult($systemErrors, $fileDiffs);
189+
return new ProcessResult($systemErrors, $fileDiffs, $totalChanged);
181190
}
182191
}

src/Parallel/ValueObject/Bridge.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@ final class Bridge
2828
* @var string
2929
*/
3030
public const FILES_COUNT = 'files_count';
31+
/**
32+
* @var string
33+
*/
34+
public const TOTAL_CHANGED = 'total_changed';
3135
}

src/ValueObject/FileProcessResult.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ final class FileProcessResult
1717
* @readonly
1818
*/
1919
private ?FileDiff $fileDiff;
20+
/**
21+
* @readonly
22+
*/
23+
private bool $hasChanged;
2024
/**
2125
* @param SystemError[] $systemErrors
2226
*/
23-
public function __construct(array $systemErrors, ?FileDiff $fileDiff)
27+
public function __construct(array $systemErrors, ?FileDiff $fileDiff, bool $hasChanged)
2428
{
2529
$this->systemErrors = $systemErrors;
2630
$this->fileDiff = $fileDiff;
31+
$this->hasChanged = $hasChanged;
2732
Assert::allIsInstanceOf($systemErrors, SystemError::class);
2833
}
2934
/**
@@ -37,4 +42,8 @@ public function getFileDiff(): ?FileDiff
3742
{
3843
return $this->fileDiff;
3944
}
45+
public function hasChanged(): bool
46+
{
47+
return $this->hasChanged;
48+
}
4049
}

src/ValueObject/ProcessResult.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,19 @@ final class ProcessResult
1717
* @readonly
1818
*/
1919
private array $fileDiffs;
20+
/**
21+
* @readonly
22+
*/
23+
private int $totalChanged;
2024
/**
2125
* @param SystemError[] $systemErrors
2226
* @param FileDiff[] $fileDiffs
2327
*/
24-
public function __construct(array $systemErrors, array $fileDiffs)
28+
public function __construct(array $systemErrors, array $fileDiffs, int $totalChanged)
2529
{
2630
$this->systemErrors = $systemErrors;
2731
$this->fileDiffs = $fileDiffs;
32+
$this->totalChanged = $totalChanged;
2833
Assert::allIsInstanceOf($systemErrors, SystemError::class);
2934
Assert::allIsInstanceOf($fileDiffs, FileDiff::class);
3035
}
@@ -53,4 +58,8 @@ public function addSystemErrors(array $systemErrors): void
5358
Assert::allIsInstanceOf($systemErrors, SystemError::class);
5459
$this->systemErrors = array_merge($this->systemErrors, $systemErrors);
5560
}
61+
public function getTotalChanged(): int
62+
{
63+
return $this->totalChanged;
64+
}
5665
}

0 commit comments

Comments
 (0)