Skip to content

RefactorCommand

github-actions edited this page Apr 23, 2026 · 1 revision

Provides functionality to execute automated code refactoring using Rector.

This class MUST NOT be extended and SHALL encapsulate the logic for Rector invocation.


Constants

Constant Visibility Type Value
CONFIG public string 'rector.php'

Methods

__construct

Creates a new RefactorCommand instance.

public __construct(\Symfony\Component\Config\FileLocatorInterface $fileLocator, \FastForward\DevTools\Process\ProcessBuilderInterface $processBuilder, \FastForward\DevTools\Process\ProcessQueueInterface $processQueue, \Psr\Log\LoggerInterface $logger): mixed

Parameters:

Parameter Type Description
$fileLocator \Symfony\Component\Config\FileLocatorInterface the file locator
$processBuilder \FastForward\DevTools\Process\ProcessBuilderInterface the process builder
$processQueue \FastForward\DevTools\Process\ProcessQueueInterface the process queue
$logger \Psr\Log\LoggerInterface the output-aware logger

configure

Configures the refactor command options and description.

protected configure(): void

This method MUST define the expected --fix option. It SHALL configure the command name and descriptions accurately.


execute

Executes the refactoring process securely.

protected execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output): int

The method MUST execute Rector securely via Process. It SHALL use dry-run mode unless the --fix option is specified. It MUST return self::SUCCESS or self::FAILURE.

Parameters:

Parameter Type Description
$input \Symfony\Component\Console\Input\InputInterface the input interface to retrieve arguments properly
$output \Symfony\Component\Console\Output\OutputInterface the output interface to log outputs

Return Value:

the status code denoting success or failure


Inherited methods

addJsonOption

Adds the standard JSON output options to the current command.

protected addJsonOption(): static

isJsonOutput

Determines whether JSON output was requested.

protected isJsonOutput(\Symfony\Component\Console\Input\InputInterface $input): bool

The pretty-json flag SHALL imply JSON output.

Parameters:

Parameter Type Description
$input \Symfony\Component\Console\Input\InputInterface

isPrettyJsonOutput

Determines whether pretty JSON output was requested.

protected isPrettyJsonOutput(\Symfony\Component\Console\Input\InputInterface $input): bool

Parameters:

Parameter Type Description
$input \Symfony\Component\Console\Input\InputInterface

Clone this wiki locally