Fast Forward Development Tools for PHP projects

PhpDocCommand extends AbstractCommand
in package

FinalYes

Provides operations to inspect, lint, and repair PHPDoc comments across the project.

The class MUST NOT be extended and SHALL coordinate tools like PHP-CS-Fixer and Rector.

Table of Contents

Constants

CONFIG  = '.php-cs-fixer.dist.php'
FILENAME  = '.docheader'

Properties

$filesystem  : Filesystem

Methods

__construct()  : mixed
Constructs a new AbstractCommand instance.
configure()  : void
Configures the PHPDoc command.
execute()  : int
Executes the PHPDoc checks and rectifications.
getAbsolutePath()  : string
Computes the absolute path for a given relative or absolute path.
getConfigFile()  : string
Determines the correct absolute path to a configuration file.
getCurrentWorkingDirectory()  : string
Retrieves the current working directory of the application.
getProjectDescription()  : string
Computes the human-readable description of the current application.
getProjectName()  : string
Computes the human-readable title or description of the current application.
getPsr4Namespaces()  : array<string|int, mixed>
Retrieves configured PSR-4 namespaces from the composer configuration.
runCommand()  : int
Configures and executes a registered console command by name.
runProcess()  : int
Executes a given system process gracefully and outputs its buffer.
ensureDocHeaderExists()  : void
Creates the missing document header configuration file if needed.
runPhpCsFixer()  : int
Executes the PHP-CS-Fixer checks internally.
runRector()  : int
Runs Rector to insert missing method block comments automatically.

Constants

CONFIG

public string CONFIG = '.php-cs-fixer.dist.php'

stores the underlying configuration file for PHP-CS-Fixer

FILENAME

public string FILENAME = '.docheader'

determines the template filename for docheaders

Properties

$filesystem read-only

protected Filesystem $filesystem

The filesystem instance used for file operations. This property MUST be utilized for interacting with the file system securely.

Methods

__construct()

Constructs a new AbstractCommand instance.

public __construct([Filesystem|null $filesystem = null ]) : mixed

The method MAY accept a Filesystem instance; if omitted, it SHALL instantiate a new one.

Parameters
$filesystem : Filesystem|null = null

the filesystem utility to use

configure()

Configures the PHPDoc command.

protected configure() : void

This method MUST securely configure the expected inputs, such as the --fix option.

execute()

Executes the PHPDoc checks and rectifications.

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

The method MUST ensure the .docheader template is present. It SHALL then invoke PHP-CS-Fixer and Rector. If both succeed, it MUST return self::SUCCESS.

Parameters
$input : InputInterface

the command input parameters

$output : OutputInterface

the system output handler

Return values
int

the success or failure state

getAbsolutePath()

Computes the absolute path for a given relative or absolute path.

protected getAbsolutePath(string $relativePath) : string

This method MUST return the exact path if it is already absolute. If relative, it SHALL make it absolute relying on the current working directory.

Parameters
$relativePath : string

the path to evaluate or resolve

Return values
string

the resolved absolute path

getConfigFile()

Determines the correct absolute path to a configuration file.

protected getConfigFile(string $filename[, bool $force = false ]) : string

The method MUST attempt to resolve the configuration file locally in the working directory. If absent and not forced, it SHALL provide the default equivalent from the package itself.

Parameters
$filename : string

the name of the configuration file

$force : bool = false

determines whether to bypass fallback and forcefully return the local file path

Return values
string

the resolved absolute path to the configuration file

getCurrentWorkingDirectory()

Retrieves the current working directory of the application.

protected getCurrentWorkingDirectory() : string

The method MUST return the initial working directory defined by the application. If not available, it SHALL fall back to the safe current working directory.

Return values
string

the absolute path to the current working directory

getProjectDescription()

Computes the human-readable description of the current application.

protected getProjectDescription() : string

The method SHOULD utilize the package description as the title, but MUST provide the raw package name as a fallback mechanism.

Return values
string

the computed title or description string

getProjectName()

Computes the human-readable title or description of the current application.

protected getProjectName() : string

The method SHOULD utilize the package description as the title, but MUST provide the raw package name as a fallback mechanism.

Return values
string

the computed title or description string

getPsr4Namespaces()

Retrieves configured PSR-4 namespaces from the composer configuration.

protected getPsr4Namespaces() : array<string|int, mixed>

This method SHALL parse the underlying composer.json using the Composer instance, and MUST provide an empty array if no specific paths exist.

Return values
array<string|int, mixed>

the PSR-4 namespaces mappings

runCommand()

Configures and executes a registered console command by name.

protected runCommand(string $commandName, array<string|int, mixed>|InputInterface $input, OutputInterface $output) : int

The method MUST look up the command from the application and run it. It SHALL ignore generic validation errors and route the custom input and output correctly.

Parameters
$commandName : string

the name of the required command

$input : array<string|int, mixed>|InputInterface

the input arguments or array definition

$output : OutputInterface

the interface for buffering output

Return values
int

the status code resulting from the dispatched command

runProcess()

Executes a given system process gracefully and outputs its buffer.

protected runProcess(Process $command, OutputInterface $output) : int

The method MUST execute the provided command ensuring the output is channeled to the OutputInterface. It SHOULD leverage TTY if supported. If the process fails, it MUST return self::FAILURE; otherwise, it SHALL return self::SUCCESS.

Parameters
$command : Process

the configured process instance to run

$output : OutputInterface

the output interface to log warnings or results

Return values
int

the status code of the command execution

ensureDocHeaderExists()

Creates the missing document header configuration file if needed.

private ensureDocHeaderExists(OutputInterface $output) : void

The method MUST query the local filesystem. If the file is missing, it SHOULD copy the tool template into the root folder.

Parameters
$output : OutputInterface

the logger where missing capabilities are announced

runPhpCsFixer()

Executes the PHP-CS-Fixer checks internally.

private runPhpCsFixer(InputInterface $input, OutputInterface $output) : int

The method SHOULD run in dry-run mode unless the fix flag is explicitly provided. It MUST return an integer describing the exit code.

Parameters
$input : InputInterface

the parsed console inputs

$output : OutputInterface

the configured outputs

Return values
int

the status result of the underlying process

runRector()

Runs Rector to insert missing method block comments automatically.

private runRector(InputInterface $input, OutputInterface $output) : int

The method MUST apply the AddMissingMethodPhpDocRector constraint locally. It SHALL strictly return an integer denoting success or failure.

Parameters
$input : InputInterface

the incoming console parameters

$output : OutputInterface

the outgoing console display

Return values
int

the code indicating the process result


        
On this page

Search results