PhpDocCommand

Class
extends AbstractCommand
Final: Yes

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

Description

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

Attributes
#[AsCommand]
$name : 'phpdoc'
$description : 'Checks and fixes PHPDocs.'
$help : 'This command checks and fixes PHPDocs in your PHP files.'

Table of Contents

Constants

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

Properties

Methods

__construct()

Creates a new PhpDocCommand instance.

 : mixed
configure()

Configures the PHPDoc command.

 : void
execute()

Executes the PHPDoc checks and rectifications.

 : int
getAbsolutePath()

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

 : string
getConfigFile()

Determines the correct absolute path to a configuration file.

 : string
getCurrentWorkingDirectory()

Retrieves the current working directory of the application.

 : string
getDevToolsFile()

Resolves the absolute path to a file within the fast-forward/dev-tools package.

 : string
runCommand()

Configures and executes a registered console command by name.

 : int
runProcess()

Executes a given system process gracefully and outputs its buffer.

 : int
ensureDocHeaderExists()

Creates the missing document header configuration file if needed.

 : void
runPhpCsFixer()

Executes the PHP-CS-Fixer checks internally.

 : int
runRector()

Runs Rector to insert missing method block comments automatically.

 : int
Constants

Constants

CONFIG

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

Description

stores the underlying configuration file for PHP-CS-Fixer

FILENAME

Public
public string FILENAME = '.docheader'

Description

determines the template filename for docheaders

Properties

$filesystem

Protected Read-only
protected Filesystem $filesystem
Methods

__construct()

Public

Creates a new PhpDocCommand instance.

public __construct(ComposerJson  $composerJson, Filesystem  $filesystem) : mixed
Parameters
$composerJson : ComposerJson

Description

the composer.json accessor

$filesystem : Filesystem

Description

the filesystem component

configure()

Protected

Configures the PHPDoc command.

protected configure() : void

Description

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

execute()

Protected

Executes the PHPDoc checks and rectifications.

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

Description

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

Description

the command input parameters

$output : OutputInterface

Description

the system output handler

Return values
int

Description

the success or failure state

getAbsolutePath()

Protected

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

protected getAbsolutePath( string  $relativePath) : string

Description

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

Description

the path to evaluate or resolve

Return values
string

Description

the resolved absolute path

getConfigFile()

Protected

Determines the correct absolute path to a configuration file.

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

Description

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

Description

the name of the configuration file

$force : bool = false

Description

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

Return values
string

Description

the resolved absolute path to the configuration file

getCurrentWorkingDirectory()

Protected

Retrieves the current working directory of the application.

protected getCurrentWorkingDirectory() : string

Description

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

Description

the absolute path to the current working directory

getDevToolsFile()

Protected

Resolves the absolute path to a file within the fast-forward/dev-tools package.

protected getDevToolsFile( string  $filename) : string

Description

This method uses Composer's InstalledVersions to determine the installation path of the fast-forward/dev-tools package and returns the absolute path to the given filename within it. It is used as a fallback when a configuration file is not found in the project root.

Parameters
$filename : string

Description

the name of the file to resolve within the dev-tools package

Return values
string

Description

the absolute path to the file inside the dev-tools package

runCommand()

Protected

Configures and executes a registered console command by name.

protected runCommand( string  $command, OutputInterface  $output) : int

Description

The method MUST run the specified command with the provided input and output interfaces.

Parameters
$command : string

Description

the commandline name of the command to execute

$output : OutputInterface

Description

the interface for buffering output

Return values
int

Description

the status code resulting from the dispatched command

runProcess()

Protected

Executes a given system process gracefully and outputs its buffer.

protected runProcess(Process  $command, OutputInterface  $output[, bool  $tty = true]) : int

Description

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

Description

the configured process instance to run

$output : OutputInterface

Description

the output interface to log warnings or results

$tty : bool = true
Return values
int

Description

the status code of the command execution

ensureDocHeaderExists()

Private

Creates the missing document header configuration file if needed.

private ensureDocHeaderExists(OutputInterface  $output) : void

Description

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

Description

the logger where missing capabilities are announced

runPhpCsFixer()

Private

Executes the PHP-CS-Fixer checks internally.

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

Description

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

Description

the parsed console inputs

$output : OutputInterface

Description

the configured outputs

Return values
int

Description

the status result of the underlying process

runRector()

Private

Runs Rector to insert missing method block comments automatically.

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

Description

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

Parameters
$input : InputInterface

Description

the incoming console parameters

$output : OutputInterface

Description

the outgoing console display

Return values
int

Description

the code indicating the process result