8000 [Application] Move autoload and paths setup to ApplicationFileProcessor by samsonasik · Pull Request #6915 · rectorphp/rector-src · GitHub
[go: up one dir, main page]

Skip to content

[Application] Move autoload and paths setup to ApplicationFileProcessor #6915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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
10000
17 changes: 15 additions & 2 deletions src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use Nette\Utils\FileSystem as UtilsFileSystem;
use PHPStan\Parser\ParserErrorsException;
use Rector\Application\Provider\CurrentFileProvider;
use Rector\Autoloading\AdditionalAutoloader;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\FileSystem\FilesFinder;
use Rector\Parallel\Application\ParallelFileProcessor;
use Rector\PhpParser\Parser\ParserErrors;
use Rector\Reporting\MissConfigurationReporter;
use Rector\StaticReflection\DynamicSourceLocatorDecorator;
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Rector\Util\ArrayParametersMerger;
use Rector\ValueObject\Application\File;
Expand Down Expand Up @@ -52,6 +54,8 @@ public function __construct(
private readonly FileProcessor $fileProcessor,
private readonly ArrayParametersMerger $arrayParametersMerger,
private readonly MissConfigurationReporter $missConfigurationReporter,
private readonly AdditionalAutoloader $additionalAutoloader,
private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator
) {
}

Expand Down Expand Up @@ -97,7 +101,7 @@ public function run(Configuration $configuration, InputInterface $input): Proces
if ($configuration->isParallel()) {
$processResult = $this->runParallel($filePaths, $input, $postFileCallback);
} else {
$processResult = $this->processFiles($filePaths, $configuration, $preFileCallback, $postFileCallback);
$processResult = $this->processFiles($filePaths, $configuration, $preFileCallback, $postFileCallback, $input);
}

$processResult->addSystemErrors($this->systemErrors);
Expand All @@ -116,14 +120,23 @@ public function processFiles(
array $filePaths,
Configuration $configuration,
?callable $preFileCallback = null,
?callable $postFileCallback = null
?callable $postFileCallback = null,
?InputInterface $input = null
): ProcessResult {
/** @var SystemError[] $systemErrors */
$systemErrors = [];

/** @var FileDiff[] $fileDiffs */
$fileDiffs = [];

// avoid registered autoload input setup gone on parallel
if ($input instanceof InputInterface) {
$this->additionalAutoloader->autoloadInput($input);
}

$this->additionalAutoloader->autoloadPaths();
$this->dynamicSourceLocatorDecorator->addPaths($configuration->getPaths());

foreach ($filePaths as $filePath) {
if ($preFileCallback !== null) {
$preFileCallback($filePath);
Expand Down
5 changes: 0 additions & 5 deletions src/Console/Command/ProcessCommand.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\Console\Command;

use Rector\Application\ApplicationFileProcessor;
use Rector\Autoloading\AdditionalAutoloader;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\Configuration\ConfigInitializer;
Expand Down Expand Up @@ -33,7 +32,6 @@
final class ProcessCommand extends Command
{
public function __construct(
private readonly AdditionalAutoloader $additionalAutoloader,
private readonly ChangedFilesDetector $changedFilesDetector,
private readonly ConfigInitializer $configInitializer,
private readonly ApplicationFileProcessor $applicationFileProcessor,
Expand Down Expand Up @@ -95,9 +93,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->symfonyStyle->setVerbosity(OutputInterface::VERBOSITY_QUIET);
}

$this->additionalAutoloader->autoloadInput($input);
$this->additionalAutoloader->autoloadPaths();

$paths = $configuration->getPaths();

// 0. warn about too high levels
Expand Down
14 changes: 7 additions & 7 deletions src/Console/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Rector\Configuration\ConfigurationRuleFilter;
use Rector\Console\ProcessConfigureDecorator;
use Rector\Parallel\ValueObject\Bridge;
use Rector\StaticReflection\DynamicSourceLocatorDecorator;
use Rector\Util\MemoryLimiter;
use Rector\ValueObject\Configuration;
use Rector\ValueObject\Error\SystemError;
Expand Down Expand Up @@ -42,7 +41,6 @@ final class WorkerCommand extends Command
private const RESULT = 'result';

public function __construct(
private readonly DynamicSourceLocatorDecorator $dynamicSourceLocatorDecorator,
private readonly ApplicationFileProcessor $applicationFileProcessor,
private readonly MemoryLimiter $memoryLimiter,
private readonly ConfigurationFactory $configurationFactory,
Expand Down Expand Up @@ -76,6 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$promise->then(function (ConnectionInterface $connection) use (
$parallelIdentifier,
$configuration,
$input,
$output
): void {
$inDecoder = new Decoder($connection, true, 512, JSON_INVALID_UTF8_IGNORE);
Expand All @@ -86,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
ReactCommand::IDENTIFIER => $parallelIdentifier,
]);

$this->runWorker($outEncoder, $inDecoder, $configuration, $output);
$this->runWorker($outEncoder, $inDecoder, $configuration, $input, $output);
});

$streamSelectLoop->run();
Expand All @@ -98,10 +97,9 @@ private function runWorker(
Encoder $encoder,
Decoder $decoder,
Configuration $configuration,
InputInterface $input,
OutputInterface $output
): void {
$this->dynamicSourceLocatorDecorator->addPaths($configuration->getPaths());

if ($configuration->isDebug()) {
$preFileCallback = static function (string $filePath) use ($output): void {
$output->writeln($filePath);
Expand All @@ -128,7 +126,7 @@ private function runWorker(
$encoder->on(ReactEvent::ERROR, $handleErrorCallback);

// 2. collect diffs + errors from file processor
$decoder->on(ReactEvent::DATA, function (array $json) use ($preFileCallback, $encoder, $configuration): void {
$decoder->on(ReactEvent::DATA, function (array $json) use ($preFileCallback, $encoder, $configuration, $input): void {
$action = $json[ReactCommand::ACTION];
if ($action !== Action::MAIN) {
return;
Expand All @@ -142,7 +140,9 @@ private function runWorker(
$processResult = $this->applicationFileProcessor->processFiles(
$filePaths,
$configuration,
$preFileCallback
$preFileCallback,
null,
$input,
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function setFilePath(string $filePath): void
*/
public function addFiles(array $files): void
{
$this->filePaths = array_merge($this->filePaths, $files);
$this->filePaths = array_unique(array_merge($this->filePaths, $files));
}

/**
* @param string[] $directories
*/
public function addDirectories(array $directories): void
{
$this->directories = array_merge($this->directories, $directories);
$this->directories = array_unique(array_merge($this->directories, $directories));
}

public function provide(): SourceLocator
Expand Down
0