mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
Updated Rector to commit 58ef131772f7745a52c3990aeaea34a4892b6ae5
58ef131772
[Performance] Remove CollectedData on ProcessResult (#5520)
This commit is contained in:
parent
89c895d127
commit
c828305041
@ -4,7 +4,6 @@ declare (strict_types=1);
|
||||
namespace Rector\Application;
|
||||
|
||||
use RectorPrefix202401\Nette\Utils\FileSystem as UtilsFileSystem;
|
||||
use PHPStan\Collectors\CollectedData;
|
||||
use Rector\Caching\Detector\ChangedFilesDetector;
|
||||
use Rector\Configuration\Option;
|
||||
use Rector\Configuration\Parameter\SimpleParameterProvider;
|
||||
@ -97,7 +96,7 @@ final class ApplicationFileProcessor
|
||||
$filePaths = $this->fileFactory->findFilesInPaths($configuration->getPaths(), $configuration);
|
||||
// no files found
|
||||
if ($filePaths === []) {
|
||||
return new ProcessResult([], [], []);
|
||||
return new ProcessResult([], []);
|
||||
}
|
||||
$this->configureCustomErrorHandler();
|
||||
/**
|
||||
@ -142,8 +141,6 @@ final class ApplicationFileProcessor
|
||||
$systemErrors = [];
|
||||
/** @var FileDiff[] $fileDiffs */
|
||||
$fileDiffs = [];
|
||||
/** @var CollectedData[] $collectedData */
|
||||
$collectedData = [];
|
||||
foreach ($filePaths as $filePath) {
|
||||
if ($preFileCallback !== null) {
|
||||
$preFileCallback($filePath);
|
||||
@ -168,7 +165,7 @@ final class ApplicationFileProcessor
|
||||
$systemErrors[] = $this->resolveSystemError($throwable, $filePath);
|
||||
}
|
||||
}
|
||||
return new ProcessResult($systemErrors, $fileDiffs, $collectedData);
|
||||
return new ProcessResult($systemErrors, $fileDiffs);
|
||||
}
|
||||
private function processFile(File $file, Configuration $configuration) : FileProcessResult
|
||||
{
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '0.19.5';
|
||||
public const PACKAGE_VERSION = '58ef131772f7745a52c3990aeaea34a4892b6ae5';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-01-29 23:50:30';
|
||||
public const RELEASE_DATE = '2024-01-30 12:35:43';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -3,8 +3,8 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Autoloading;
|
||||
|
||||
use Phar;
|
||||
use FilesystemIterator;
|
||||
use Phar;
|
||||
use Rector\Configuration\Option;
|
||||
use Rector\Configuration\Parameter\SimpleParameterProvider;
|
||||
use Rector\Exception\ShouldNotHappenException;
|
||||
|
@ -270,7 +270,8 @@ final class RectorConfigBuilder
|
||||
}
|
||||
}
|
||||
throw new InvalidConfigurationException(\sprintf('We could not find local "composer.json" to determine your PHP version.%sPlease, fill the PHP version set in withPhpSets() manually.', \PHP_EOL));
|
||||
} elseif ($php53) {
|
||||
}
|
||||
if ($php53) {
|
||||
$this->sets[] = LevelSetList::UP_TO_PHP_53;
|
||||
} elseif ($php54) {
|
||||
$this->sets[] = LevelSetList::UP_TO_PHP_54;
|
||||
|
@ -5,7 +5,6 @@ namespace Rector\Console\Command;
|
||||
|
||||
use RectorPrefix202401\Clue\React\NDJson\Decoder;
|
||||
use RectorPrefix202401\Clue\React\NDJson\Encoder;
|
||||
use PHPStan\Collectors\CollectedData;
|
||||
use RectorPrefix202401\React\EventLoop\StreamSelectLoop;
|
||||
use RectorPrefix202401\React\Socket\ConnectionInterface;
|
||||
use RectorPrefix202401\React\Socket\TcpConnector;
|
||||
@ -113,19 +112,6 @@ final class WorkerCommand extends Command
|
||||
if ($action !== Action::MAIN) {
|
||||
return;
|
||||
}
|
||||
$previouslyCollectedDataItems = $json[Bridge::PREVIOUSLY_COLLECTED_DATA] ?? [];
|
||||
if ($previouslyCollectedDataItems !== []) {
|
||||
// turn to value objects
|
||||
$previouslyCollectedDatas = [];
|
||||
foreach ($previouslyCollectedDataItems as $previouslyCollectedDataItem) {
|
||||
Assert::keyExists($previouslyCollectedDataItem, 'data');
|
||||
Assert::keyExists($previouslyCollectedDataItem, 'filePath');
|
||||
Assert::keyExists($previouslyCollectedDataItem, 'collectorType');
|
||||
$previouslyCollectedDatas[] = CollectedData::decode($previouslyCollectedDataItem);
|
||||
}
|
||||
$configuration->setCollectedData($previouslyCollectedDatas);
|
||||
$configuration->enableSecondRun();
|
||||
}
|
||||
/** @var string[] $filePaths */
|
||||
$filePaths = $json[Bridge::FILES] ?? [];
|
||||
Assert::notEmpty($filePaths);
|
||||
@ -133,7 +119,7 @@ final class WorkerCommand extends Command
|
||||
/**
|
||||
* this invokes all listeners listening $decoder->on(...) @see \Symplify\EasyParallel\Enum\ReactEvent::DATA
|
||||
*/
|
||||
$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::COLLECTED_DATA => $processResult->getCollectedData()]]);
|
||||
$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())]]);
|
||||
});
|
||||
$decoder->on(ReactEvent::ERROR, $handleErrorCallback);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ namespace Rector\Parallel\Application;
|
||||
use RectorPrefix202401\Clue\React\NDJson\Decoder;
|
||||
use RectorPrefix202401\Clue\React\NDJson\Encoder;
|
||||
use RectorPrefix202401\Nette\Utils\Random;
|
||||
use PHPStan\Collectors\CollectedData;
|
||||
use RectorPrefix202401\React\EventLoop\StreamSelectLoop;
|
||||
use RectorPrefix202401\React\Socket\ConnectionInterface;
|
||||
use RectorPrefix202401\React\Socket\TcpServer;
|
||||
@ -73,16 +72,14 @@ final class ParallelFileProcessor
|
||||
// initial counters
|
||||
/** @var FileDiff[] $fileDiffs */
|
||||
$fileDiffs = [];
|
||||
/** @var CollectedData[] $collectedData */
|
||||
$collectedData = [];
|
||||
/** @var SystemError[] $systemErrors */
|
||||
$systemErrors = [];
|
||||
$tcpServer = new TcpServer('127.0.0.1:0', $streamSelectLoop);
|
||||
$this->processPool = new ProcessPool($tcpServer);
|
||||
$tcpServer->on(ReactEvent::CONNECTION, function (ConnectionInterface $connection) use(&$jobs, $configuration) : void {
|
||||
$tcpServer->on(ReactEvent::CONNECTION, function (ConnectionInterface $connection) use(&$jobs) : void {
|
||||
$inDecoder = new Decoder($connection, \true, 512, 0, 4 * 1024 * 1024);
|
||||
$outEncoder = new Encoder($connection);
|
||||
$inDecoder->on(ReactEvent::DATA, function (array $data) use(&$jobs, $inDecoder, $outEncoder, $configuration) : void {
|
||||
$inDecoder->on(ReactEvent::DATA, function (array $data) use(&$jobs, $inDecoder, $outEncoder) : void {
|
||||
$action = $data[ReactCommand::ACTION];
|
||||
if ($action !== Action::HELLO) {
|
||||
return;
|
||||
@ -95,7 +92,7 @@ final class ParallelFileProcessor
|
||||
return;
|
||||
}
|
||||
$jobsChunk = \array_pop($jobs);
|
||||
$parallelProcess->request([ReactCommand::ACTION => Action::MAIN, Content::FILES => $jobsChunk, Bridge::PREVIOUSLY_COLLECTED_DATA => $configuration->getCollectedData()]);
|
||||
$parallelProcess->request([ReactCommand::ACTION => Action::MAIN, Content::FILES => $jobsChunk]);
|
||||
});
|
||||
});
|
||||
/** @var string $serverAddress */
|
||||
@ -116,14 +113,14 @@ final class ParallelFileProcessor
|
||||
};
|
||||
$timeoutInSeconds = SimpleParameterProvider::provideIntParameter(Option::PARALLEL_JOB_TIMEOUT_IN_SECONDS);
|
||||
$fileChunksBudgetPerProcess = [];
|
||||
$processSpawner = function () use(&$systemErrors, &$fileDiffs, &$collectedData, &$jobs, $postFileCallback, &$systemErrorsCount, &$reachedInternalErrorsCountLimit, $mainScript, $input, $serverPort, $streamSelectLoop, $timeoutInSeconds, $handleErrorCallable, &$fileChunksBudgetPerProcess, &$processSpawner) : void {
|
||||
$processSpawner = function () use(&$systemErrors, &$fileDiffs, &$jobs, $postFileCallback, &$systemErrorsCount, &$reachedInternalErrorsCountLimit, $mainScript, $input, $serverPort, $streamSelectLoop, $timeoutInSeconds, $handleErrorCallable, &$fileChunksBudgetPerProcess, &$processSpawner) : void {
|
||||
$processIdentifier = Random::generate();
|
||||
$workerCommandLine = $this->workerCommandLineFactory->create($mainScript, ProcessCommand::class, 'worker', $input, $processIdentifier, $serverPort);
|
||||
$fileChunksBudgetPerProcess[$processIdentifier] = self::MAX_CHUNKS_PER_WORKER;
|
||||
$parallelProcess = new ParallelProcess($workerCommandLine, $streamSelectLoop, $timeoutInSeconds);
|
||||
$parallelProcess->start(
|
||||
// 1. callable on data
|
||||
function (array $json) use($parallelProcess, &$systemErrors, &$fileDiffs, &$jobs, $postFileCallback, &$systemErrorsCount, &$collectedData, &$reachedInternalErrorsCountLimit, $processIdentifier, &$fileChunksBudgetPerProcess, &$processSpawner) : void {
|
||||
function (array $json) use($parallelProcess, &$systemErrors, &$fileDiffs, &$jobs, $postFileCallback, &$systemErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier, &$fileChunksBudgetPerProcess, &$processSpawner) : void {
|
||||
// decode arrays to objects
|
||||
foreach ($json[Bridge::SYSTEM_ERRORS] as $jsonError) {
|
||||
if (\is_string($jsonError)) {
|
||||
@ -135,9 +132,6 @@ final class ParallelFileProcessor
|
||||
foreach ($json[Bridge::FILE_DIFFS] as $jsonFileDiff) {
|
||||
$fileDiffs[] = FileDiff::decode($jsonFileDiff);
|
||||
}
|
||||
foreach ($json[Bridge::COLLECTED_DATA] as $collectedDataItem) {
|
||||
$collectedData[] = CollectedData::decode($collectedDataItem);
|
||||
}
|
||||
$postFileCallback($json[Bridge::FILES_COUNT]);
|
||||
$systemErrorsCount += $json[Bridge::SYSTEM_ERRORS_COUNT];
|
||||
if ($systemErrorsCount >= self::SYSTEM_ERROR_LIMIT) {
|
||||
@ -185,6 +179,6 @@ final class ParallelFileProcessor
|
||||
if ($reachedSystemErrorsCountLimit) {
|
||||
$systemErrors[] = new SystemError(\sprintf('Reached system errors count limit of %d, exiting...', self::SYSTEM_ERROR_LIMIT));
|
||||
}
|
||||
return new ProcessResult($systemErrors, $fileDiffs, $collectedData);
|
||||
return new ProcessResult($systemErrors, $fileDiffs);
|
||||
}
|
||||
}
|
||||
|
@ -28,12 +28,4 @@ final class Bridge
|
||||
* @var string
|
||||
*/
|
||||
public const FILES_COUNT = 'files_count';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const COLLECTED_DATA = 'collected_data';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PREVIOUSLY_COLLECTED_DATA = 'previously_collected_data';
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\ValueObject;
|
||||
|
||||
use PHPStan\Collectors\CollectedData;
|
||||
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
|
||||
use RectorPrefix202401\Webmozart\Assert\Assert;
|
||||
final class Configuration
|
||||
@ -68,14 +67,6 @@ final class Configuration
|
||||
* @var bool
|
||||
*/
|
||||
private $isDebug = \false;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
private $isSecondRun = \false;
|
||||
/**
|
||||
* @var CollectedData[]
|
||||
*/
|
||||
private $collectedData = [];
|
||||
/**
|
||||
* @param string[] $fileExtensions
|
||||
* @param string[] $paths
|
||||
@ -150,39 +141,4 @@ final class Configuration
|
||||
{
|
||||
return $this->isDebug;
|
||||
}
|
||||
/**
|
||||
* @param CollectedData[] $collectedData
|
||||
*/
|
||||
public function setCollectedData(array $collectedData) : void
|
||||
{
|
||||
$this->collectedData = $collectedData;
|
||||
}
|
||||
/**
|
||||
* @return CollectedData[]
|
||||
*/
|
||||
public function getCollectedData() : array
|
||||
{
|
||||
return $this->collectedData;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function enableSecondRun() : void
|
||||
{
|
||||
$this->isSecondRun = \true;
|
||||
}
|
||||
/**
|
||||
* @api
|
||||
*/
|
||||
public function isSecondRun() : bool
|
||||
{
|
||||
return $this->isSecondRun;
|
||||
}
|
||||
/**
|
||||
* @api used in tests
|
||||
*/
|
||||
public function reset() : void
|
||||
{
|
||||
$this->isSecondRun = \false;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\ValueObject;
|
||||
|
||||
use PHPStan\Collectors\CollectedData;
|
||||
use Rector\ValueObject\Error\SystemError;
|
||||
use Rector\ValueObject\Reporting\FileDiff;
|
||||
use RectorPrefix202401\Webmozart\Assert\Assert;
|
||||
@ -18,24 +17,16 @@ final class ProcessResult
|
||||
* @readonly
|
||||
*/
|
||||
private $fileDiffs;
|
||||
/**
|
||||
* @var CollectedData[]
|
||||
* @readonly
|
||||
*/
|
||||
private $collectedData;
|
||||
/**
|
||||
* @param SystemError[] $systemErrors
|
||||
* @param FileDiff[] $fileDiffs
|
||||
* @param CollectedData[] $collectedData
|
||||
*/
|
||||
public function __construct(array $systemErrors, array $fileDiffs, array $collectedData)
|
||||
public function __construct(array $systemErrors, array $fileDiffs)
|
||||
{
|
||||
$this->systemErrors = $systemErrors;
|
||||
$this->fileDiffs = $fileDiffs;
|
||||
$this->collectedData = $collectedData;
|
||||
Assert::allIsInstanceOf($systemErrors, SystemError::class);
|
||||
Assert::allIsInstanceOf($fileDiffs, FileDiff::class);
|
||||
Assert::allIsInstanceOf($collectedData, CollectedData::class);
|
||||
}
|
||||
/**
|
||||
* @return SystemError[]
|
||||
@ -51,13 +42,6 @@ final class ProcessResult
|
||||
{
|
||||
return $this->fileDiffs;
|
||||
}
|
||||
/**
|
||||
* @return CollectedData[]
|
||||
*/
|
||||
public function getCollectedData() : array
|
||||
{
|
||||
return $this->collectedData;
|
||||
}
|
||||
/**
|
||||
* @param SystemError[] $systemErrors
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user