Skip to content

Commit

Permalink
[DX] Add ProcessConfigureDecorator to avoid superfluous composition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 9, 2023
1 parent 6942dab commit 6b84177
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 19 deletions.
8 changes: 6 additions & 2 deletions packages/Skipper/Skipper/Skipper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ public function shouldSkipElementAndFilePath(string | object $element, string $f
/**
* @param class-string<RectorInterface> $rectorClass
*/
public function shouldSkipCurrentNode(string | object $element, string $filePath, string $rectorClass, Node $node): bool
{
public function shouldSkipCurrentNode(
string | object $element,
string $filePath,
string $rectorClass,
Node $node
): bool {
if ($this->shouldSkipElementAndFilePath($element, $filePath)) {
return true;
}
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,6 @@ parameters:
# reflection property change
-
message: '#\$this as argument is not allowed\. Refactor method to service composition#'
path: src/Console/ConsoleApplication.php
paths:
- src/Console/ConsoleApplication.php
- src/Console/Command
6 changes: 5 additions & 1 deletion src/Console/Command/ProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@
use Rector\Core\Configuration\Option;
use Rector\Core\Console\ExitCode;
use Rector\Core\Console\Output\OutputFormatterCollector;
use Rector\Core\Console\ProcessConfigureDecorator;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\StaticReflection\DynamicSourceLocatorDecorator;
use Rector\Core\Util\MemoryLimiter;
use Rector\Core\ValueObject\Configuration;
use Rector\Core\ValueObject\ProcessResult;
use Rector\Core\ValueObjectFactory\ProcessResultFactory;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

final class ProcessCommand extends AbstractProcessCommand
final class ProcessCommand extends Command
{
public function __construct(
private readonly AdditionalAutoloader $additionalAutoloader,
Expand All @@ -46,6 +48,8 @@ protected function configure(): void
$this->setName('process');
$this->setDescription('Upgrades or refactors source code with provided rectors');

ProcessConfigureDecorator::decorate($this);

parent::configure();
}

Expand Down
7 changes: 6 additions & 1 deletion src/Console/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
use React\Socket\ConnectionInterface;
use React\Socket\TcpConnector;
use Rector\Core\Configuration\ConfigurationFactory;
use Rector\Core\Console\ProcessConfigureDecorator;
use Rector\Core\Util\MemoryLimiter;
use Rector\Parallel\WorkerRunner;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symplify\EasyParallel\Enum\Action;
Expand All @@ -24,7 +26,7 @@
* ↓↓↓
* https://github.com/phpstan/phpstan-src/commit/b84acd2e3eadf66189a64fdbc6dd18ff76323f67#diff-7f625777f1ce5384046df08abffd6c911cfbb1cfc8fcb2bdeaf78f337689e3e2
*/
final class WorkerCommand extends AbstractProcessCommand
final class WorkerCommand extends Command
{
public function __construct(
private readonly WorkerRunner $workerRunner,
Expand All @@ -38,6 +40,9 @@ protected function configure(): void
{
$this->setName('worker');
$this->setDescription('[INTERNAL] Support for parallel process');

ProcessConfigureDecorator::decorate($this);

parent::configure();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,67 @@

declare(strict_types=1);

namespace Rector\Core\Console\Command;
namespace Rector\Core\Console;

use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\Core\Configuration\Option;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

abstract class AbstractProcessCommand extends Command
final class ProcessConfigureDecorator
{
protected function configure(): void
public static function decorate(Command $command): void
{
$this->addArgument(
$command->addArgument(
Option::SOURCE,
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
'Files or directories to be upgraded.'
);

$this->addOption(
$command->addOption(
Option::DRY_RUN,
Option::DRY_RUN_SHORT,
InputOption::VALUE_NONE,
'Only see the diff of changes, do not save them to files.'
);

$this->addOption(
$command->addOption(
Option::AUTOLOAD_FILE,
Option::AUTOLOAD_FILE_SHORT,
InputOption::VALUE_REQUIRED,
'Path to file with extra autoload (will be included)'
);

$this->addOption(
$command->addOption(
Option::NO_PROGRESS_BAR,
null,
InputOption::VALUE_NONE,
'Hide progress bar. Useful e.g. for nicer CI output.'
);

$this->addOption(
$command->addOption(
Option::NO_DIFFS,
null,
InputOption::VALUE_NONE,
'Hide diffs of changed files. Useful e.g. for nicer CI output.'
);

$this->addOption(
$command->addOption(
Option::OUTPUT_FORMAT,
null,
InputOption::VALUE_REQUIRED,
'Select output format',
ConsoleOutputFormatter::NAME
);

$this->addOption(Option::DEBUG, null, InputOption::VALUE_NONE, 'Display debug output.');
$command->addOption(Option::DEBUG, null, InputOption::VALUE_NONE, 'Display debug output.');

$this->addOption(Option::MEMORY_LIMIT, null, InputOption::VALUE_REQUIRED, 'Memory limit for process');
$command->addOption(Option::MEMORY_LIMIT, null, InputOption::VALUE_REQUIRED, 'Memory limit for process');

$this->addOption(Option::CLEAR_CACHE, null, InputOption::VALUE_NONE, 'Clear unchanged files cache');
$command->addOption(Option::CLEAR_CACHE, null, InputOption::VALUE_NONE, 'Clear unchanged files cache');

$this->addOption(Option::PARALLEL_PORT, null, InputOption::VALUE_REQUIRED);
$this->addOption(Option::PARALLEL_IDENTIFIER, null, InputOption::VALUE_REQUIRED);
$command->addOption(Option::PARALLEL_PORT, null, InputOption::VALUE_REQUIRED);
$command->addOption(Option::PARALLEL_IDENTIFIER, null, InputOption::VALUE_REQUIRED);
}
}

0 comments on commit 6b84177

Please sign in to comment.