Provides functionality to execute automated code refactoring using Rector.
Description
This class MUST NOT be extended and SHALL encapsulate the logic for Rector invocation.
'refactor'
'Runs Rector for code refactoring.'
['rector']
'This command runs Rector to refactor your code.'
Interfaces
Defines the logger contract consumed by reusable command result helpers.
Constants
Properties
Methods
Creates a new RefactorCommand instance.
Adds the standard JSON output options to the current command.
Configures the refactor command options and description.
Executes the refactoring process securely.
Determines whether JSON output was requested.
Determines whether pretty JSON output was requested.
Logs a failed command result and returns the failure exit code.
Logs an informational command message at notice level.
Logs a successful command result and returns the success exit code.
private
FileLocatorInterface
$fileLocator
private
LoggerInterface
$logger
private
ProcessBuilderInterface
$processBuilder
private
ProcessQueueInterface
$processQueue
Creates a new RefactorCommand instance.
public
__construct(FileLocatorInterface
$fileLocator, ProcessBuilderInterface
$processBuilder, ProcessQueueInterface
$processQueue, LoggerInterface
$logger) : mixed
Parameters
$fileLocator
:
FileLocatorInterface
Description
the file locator
Description
the process builder
Description
the process queue
$logger
:
LoggerInterface
Description
the output-aware logger
Adds the standard JSON output options to the current command.
protected
addJsonOption() : static
Return values
Configures the refactor command options and description.
protected
configure() : void
Description
This method MUST define the expected --fix option. It SHALL configure the command name
and descriptions accurately.
Executes the refactoring process securely.
protected
execute(InputInterface
$input, OutputInterface
$output) : int
Description
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
$input
:
InputInterface
Description
the input interface to retrieve arguments properly
$output
:
OutputInterface
Description
the output interface to log outputs
Return values
Description
the status code denoting success or failure
Determines whether JSON output was requested.
protected
isJsonOutput(InputInterface
$input) : bool
Description
The pretty-json flag SHALL imply JSON output.
Parameters
$input
:
InputInterface
Return values
Determines whether pretty JSON output was requested.
protected
isPrettyJsonOutput(InputInterface
$input) : bool
Parameters
$input
:
InputInterface
Return values
Logs a failed command result and returns the failure exit code.
private
failure(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []][,
string|null
$file = null][,
int|null
$line = null]) : int
Parameters
$message
:
string
Description
the failure message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
$file
:
string|null
=
null
Description
the related file path when known
$line
:
int|null
=
null
Description
the related line when known
Return values
Logs an informational command message at notice level.
private
notice(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []]) : void
Parameters
$message
:
string
Description
the notice message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
Logs a successful command result and returns the success exit code.
private
success(
string
$message, InputInterface
$input[,
array<string, mixed>
$context = []][,
string
$logLevel = LogLevel::INFO]) : int
Parameters
$message
:
string
Description
the success message
$input
:
InputInterface
Description
the originating command input
$context
:
array<string, mixed>
=
[]
Description
optional extra log context
$logLevel
:
string
=
LogLevel::INFO
Description
the PSR-3 log level used for the successful result