CodeStyleCommand

Class
extends BaseCommand
Final: Yes

Represents the command responsible for checking and fixing code style issues.

Description

This class MUST NOT be overridden and SHALL rely on external tools like ECS and Composer Normalize.

Attributes
#[AsCommand]
$name : 'code-style'
$description : 'Checks and fixes code style issues using EasyCodingStandard and Composer Normalize.'
$help : 'This command runs EasyCodingStandard and Composer Normalize to check and fix code style issues.'

Table of Contents

Interfaces

LoggerAwareCommandInterface

Defines the logger contract consumed by reusable command result helpers.

Constants

 = 'ecs.php'

Properties

Methods

__construct()

Constructs a new command instance responsible for orchestrating code style checks.

 : mixed
addJsonOption()

Adds the standard JSON output options to the current command.

 : static
configure()

Configures the current command.

 : void
execute()

Executes the code style checks and fixes block.

 : int
isJsonOutput()

Determines whether JSON output was requested.

 : bool
isPrettyJsonOutput()

Determines whether pretty JSON output was requested.

 : bool
failure()

Logs a failed command result and returns the failure exit code.

 : int
notice()

Logs an informational command message at notice level.

 : void
success()

Logs a successful command result and returns the success exit code.

 : int
Constants

Constants

CONFIG

Public
public string CONFIG = 'ecs.php'

Description

the default configuration file used for EasyCodingStandard

Properties

$fileLocator

Private Read-only
private FileLocatorInterface $fileLocator
Methods

__construct()

Public

Constructs a new command instance responsible for orchestrating code style checks.

public __construct(FileLocatorInterface  $fileLocator, ProcessBuilderInterface  $processBuilder, ProcessQueueInterface  $processQueue, LoggerInterface  $logger) : mixed

Description

The provided collaborators SHALL be used to locate the ECS configuration, build process definitions, and execute the resulting process queue. These dependencies MUST be valid service instances capable of supporting the command lifecycle expected by this class.

Parameters
$fileLocator : FileLocatorInterface

Description

locates the configuration file required by EasyCodingStandard

$processBuilder : ProcessBuilderInterface

Description

builds the process instances used to execute Composer and ECS commands

$processQueue : ProcessQueueInterface

Description

queues and executes the generated processes in the required order

$logger : LoggerInterface

Description

logs command feedback

addJsonOption()

Protected

Adds the standard JSON output options to the current command.

protected addJsonOption() : static
Return values
static

configure()

Protected

Configures the current command.

protected configure() : void

Description

This method MUST define the name, description, help text, and options for the command. It SHALL register the --fix option to allow automatic resolutions of style issues.

execute()

Protected

Executes the code style checks and fixes block.

protected execute(InputInterface  $input, OutputInterface  $output) : int

Description

The method MUST execute composer update --lock, composer normalize, and ECS using secure processes. It SHALL return self::SUCCESS if all commands succeed, or self::FAILURE otherwise.

Parameters
$input : InputInterface

Description

the input interface to retrieve options

$output : OutputInterface

Description

the output interface to log messages

Return values
int

Description

the status code of the command

isJsonOutput()

Protected

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
bool

isPrettyJsonOutput()

Protected

Determines whether pretty JSON output was requested.

protected isPrettyJsonOutput(InputInterface  $input) : bool
Parameters
$input : InputInterface
Return values
bool

failure()

Private

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
int

notice()

Private

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

success()

Private

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

Return values
int