PhpDocCommand

Class
extends Command
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 : 'standards:phpdoc'
$description : 'Checks and fixes PHPDocs.'
$aliases : ['phpdoc']

Table of Contents

Constants

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

Properties

Methods

__construct()

Creates a new PhpDocCommand instance.

 : mixed
addCacheDirOption()

Adds the standard cache directory option to the current command.

 : static
addCacheOption()

Adds the standard cache control option to the current command.

 : static
addJsonOption()

Adds the standard JSON output options to the current command.

 : static
configure()

Configures the PHPDoc command.

 : void
execute()

Executes the PHPDoc checks and rectifications.

 : int
isCacheEnabled()

Resolves whether cache writes SHOULD be enabled for the current invocation.

 : bool
isJsonOutput()

Determines whether JSON output was requested.

 : bool
isPrettyJsonOutput()

Determines whether pretty JSON output was requested.

 : bool
resolveCacheArgument()

Returns the explicit cache flag that SHOULD be forwarded to nested commands.

 : string|null
resolveCacheDirArgument()

Resolves a nested cache directory for a child command.

 : string|null
ensureDocHeaderExists()

Creates the missing document header configuration file if needed.

 : void
failure()

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

 : int
hasExplicitCacheDirArgument()

Determines whether the current invocation explicitly passed `--cache-dir`.

 : bool
isNoCacheRequested()

Determines whether cache writes were explicitly disabled for the current invocation.

 : bool
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

CACHE_FILE

Public
public string CACHE_FILE = '.php-cs-fixer.cache'

Description

defines the cache file name for PHP-CS-Fixer results

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

$clock

Private Read-only
private ClockInterface $clock

$fileLocator

Private Read-only
private FileLocatorInterface $fileLocator

$logger

Private Read-only
private LoggerInterface $logger

$renderer

Private Read-only
private Environment $renderer
Methods

__construct()

Public

Creates a new PhpDocCommand instance.

public __construct(ProcessBuilderInterface  $processBuilder, ProcessQueueInterface  $processQueue, ComposerJsonInterface  $composer, FileLocatorInterface  $fileLocator, FilesystemInterface  $filesystem, Environment  $renderer, ClockInterface  $clock, LoggerInterface  $logger) : mixed
Parameters
$processBuilder : ProcessBuilderInterface
$processQueue : ProcessQueueInterface
$composer : ComposerJsonInterface
$fileLocator : FileLocatorInterface

Description

the locator for template resources

$filesystem : FilesystemInterface

Description

the filesystem component

$renderer : Environment
$clock : ClockInterface
$logger : LoggerInterface

Description

the output-aware logger

addCacheDirOption()

Protected

Adds the standard cache directory option to the current command.

protected addCacheDirOption( string  $description, string  $default) : static
Parameters
$description : string

Description

the cache directory option description

$default : string

Description

the command-specific default cache directory

Return values
static

addCacheOption()

Protected

Adds the standard cache control option to the current command.

protected addCacheOption( string  $description) : static
Parameters
$description : string

Description

the cache option description

Return values
static

addJsonOption()

Protected

Adds the standard JSON output options to the current command.

protected addJsonOption() : static
Return values
static

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

isCacheEnabled()

Protected

Resolves whether cache writes SHOULD be enabled for the current invocation.

protected isCacheEnabled(InputInterface  $input[, bool  $default = true]) : bool
Parameters
$input : InputInterface

Description

the current command input

$default : bool = true

Description

the command-specific default cache behavior when the option is omitted

Return values
bool

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

resolveCacheArgument()

Protected

Returns the explicit cache flag that SHOULD be forwarded to nested commands.

protected resolveCacheArgument(InputInterface  $input) : string|null
Parameters
$input : InputInterface

Description

the current command input

Return values
string|null

resolveCacheDirArgument()

Protected

Resolves a nested cache directory for a child command.

protected resolveCacheDirArgument(InputInterface  $input[, string  $path = '']) : string|null
Parameters
$input : InputInterface

Description

the current command input

$path : string = ''

Description

the child cache path relative to the current command cache root

Return values
string|null

ensureDocHeaderExists()

Private

Creates the missing document header configuration file if needed.

private ensureDocHeaderExists() : void

Description

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

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

hasExplicitCacheDirArgument()

Private

Determines whether the current invocation explicitly passed `--cache-dir`.

private hasExplicitCacheDirArgument(InputInterface  $input) : bool
Parameters
$input : InputInterface

Description

the current command input

Return values
bool

isNoCacheRequested()

Private

Determines whether cache writes were explicitly disabled for the current invocation.

private isNoCacheRequested(InputInterface  $input) : bool

Description

The Composer application already provides a global --no-cache flag, so commands SHALL reuse that switch instead of redefining a local negated variant.

Parameters
$input : InputInterface

Description

the current command input

Return values
bool

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