Documentation

Plugin
in package
implements PluginInterface, EventSubscriberInterface

PHP_CodeSniffer standard installation manager.

Tags
author

Franck Nijhof franck.nijhof@dealerdirect.com

Table of Contents

Interfaces

PluginInterface
EventSubscriberInterface

Constants

KEY_MAX_DEPTH  : mixed = 'phpcodesniffer-search-depth'
MESSAGE_ERROR_WRONG_MAX_DEPTH  : mixed = 'The value of "%s" (in the composer.json "extra...
MESSAGE_NOT_INSTALLED  : mixed = 'PHPCodeSniffer is not installed'
MESSAGE_NOTHING_TO_INSTALL  : mixed = 'No PHPCS standards to install or update'
MESSAGE_PLUGIN_UNINSTALLED  : mixed = 'PHPCodeSniffer Composer Installer is uninstalled'
MESSAGE_RUNNING_INSTALLER  : mixed = 'Running PHPCodeSniffer Composer Installer'
PACKAGE_NAME  : mixed = 'squizlabs/php_codesniffer'
PACKAGE_TYPE  : mixed = 'phpcodesniffer-standard'
PHPCS_CONFIG_KEY  : mixed = 'installed_paths'
PHPCS_CONFIG_REGEX  : mixed = '`%s:[^\r\n]+`'
PLUGIN_NAME  : mixed = 'dealerdirect/phpcodesniffer-composer-installer'

Properties

$composer  : Composer
$cwd  : string
$filesystem  : Filesystem
$installedPaths  : array<string|int, mixed>
$io  : IOInterface
$processExecutor  : ProcessExecutor

Methods

activate()  : mixed
{@inheritDoc}
deactivate()  : mixed
{@inheritDoc}
getSubscribedEvents()  : mixed
{@inheritDoc}
onDependenciesChangedEvent()  : mixed
Entry point for post install and post update events.
run()  : mixed
Triggers the plugin's main functionality.
uninstall()  : mixed
{@inheritDoc}
getPhpcsCommand()  : mixed
Get the command to call PHPCS.
getPhpExecCommand()  : mixed
Get the path to the current PHP version being used.
cleanInstalledPaths()  : bool
Iterate trough all known paths and check if they are still valid.
getMaxDepth()  : int
Determines the maximum search depth when searching for Coding Standards.
getMinDepth()  : int
Returns the minimal search depth for Coding Standard packages.
getPHPCodeSnifferInstallPath()  : string
Returns the path to the PHP_CodeSniffer package installation location
getPHPCodeSnifferPackage()  : PackageInterface|null
Searches for the installed PHP_CodeSniffer Composer package
getPHPCodingStandardPackages()  : array<string|int, mixed>
Iterates through Composers' local repository looking for valid Coding Standard packages.
init()  : mixed
Prepares the plugin so it's main functionality can be run.
isPHPCodeSnifferInstalled()  : bool
Simple check if PHP_CodeSniffer is installed.
isRunningGlobally()  : bool
Test if composer is running "global" This check kinda dirty, but it is the "Composer Way"
loadInstalledPaths()  : mixed
Load all paths from PHP_CodeSniffer into an array.
saveInstalledPaths()  : int
Save all coding standard paths back into PHP_CodeSniffer
updateInstalledPaths()  : bool
Check all installed packages (including the root package) against the installed paths from PHP_CodeSniffer and add the missing ones.
verifySaveSuccess()  : int
Verify that the paths which were expected to be saved, have been.

Constants

KEY_MAX_DEPTH

public mixed KEY_MAX_DEPTH = 'phpcodesniffer-search-depth'

MESSAGE_ERROR_WRONG_MAX_DEPTH

public mixed MESSAGE_ERROR_WRONG_MAX_DEPTH = 'The value of "%s" (in the composer.json "extra".section) must be an integer larger than %d, %s given.'

MESSAGE_NOT_INSTALLED

public mixed MESSAGE_NOT_INSTALLED = 'PHPCodeSniffer is not installed'

MESSAGE_NOTHING_TO_INSTALL

public mixed MESSAGE_NOTHING_TO_INSTALL = 'No PHPCS standards to install or update'

MESSAGE_PLUGIN_UNINSTALLED

public mixed MESSAGE_PLUGIN_UNINSTALLED = 'PHPCodeSniffer Composer Installer is uninstalled'

MESSAGE_RUNNING_INSTALLER

public mixed MESSAGE_RUNNING_INSTALLER = 'Running PHPCodeSniffer Composer Installer'

PACKAGE_NAME

public mixed PACKAGE_NAME = 'squizlabs/php_codesniffer'

PACKAGE_TYPE

public mixed PACKAGE_TYPE = 'phpcodesniffer-standard'

PHPCS_CONFIG_KEY

public mixed PHPCS_CONFIG_KEY = 'installed_paths'

PHPCS_CONFIG_REGEX

public mixed PHPCS_CONFIG_REGEX = '`%s:[^\r\n]+`'

PLUGIN_NAME

public mixed PLUGIN_NAME = 'dealerdirect/phpcodesniffer-composer-installer'

Properties

$composer

private Composer $composer

$filesystem

private Filesystem $filesystem

$installedPaths

private array<string|int, mixed> $installedPaths

$processExecutor

private ProcessExecutor $processExecutor

Methods

activate()

{@inheritDoc}

public activate(Composer $composer, IOInterface $io) : mixed
Parameters
$composer : Composer
$io : IOInterface
Tags
throws
RuntimeException
LogicException
ProcessFailedException
RuntimeException

deactivate()

{@inheritDoc}

public deactivate(Composer $composer, IOInterface $io) : mixed
Parameters
$composer : Composer
$io : IOInterface

getSubscribedEvents()

{@inheritDoc}

public static getSubscribedEvents() : mixed

onDependenciesChangedEvent()

Entry point for post install and post update events.

public onDependenciesChangedEvent() : mixed
Tags
throws
InvalidArgumentException
LogicException
ProcessFailedException
RuntimeException

run()

Triggers the plugin's main functionality.

public static run(Event $event) : mixed

Makes it possible to run the plugin as a custom command.

Parameters
$event : Event
Tags
throws
InvalidArgumentException
RuntimeException
LogicException
ProcessFailedException
RuntimeException

uninstall()

{@inheritDoc}

public uninstall(Composer $composer, IOInterface $io) : mixed
Parameters
$composer : Composer
$io : IOInterface

getPhpcsCommand()

Get the command to call PHPCS.

protected getPhpcsCommand() : mixed

getPhpExecCommand()

Get the path to the current PHP version being used.

protected getPhpExecCommand() : mixed

Duplicate of the same in the EventDispatcher class in Composer itself.

cleanInstalledPaths()

Iterate trough all known paths and check if they are still valid.

private cleanInstalledPaths() : bool

If path does not exists, is not an directory or isn't readable, the path is removed from the list.

Return values
bool —

True if changes where made, false otherwise

getMaxDepth()

Determines the maximum search depth when searching for Coding Standards.

private getMaxDepth() : int
Tags
throws
InvalidArgumentException
Return values
int

getMinDepth()

Returns the minimal search depth for Coding Standard packages.

private getMinDepth() : int

Usually this is 0, unless PHP_CodeSniffer >= 3 is used.

Return values
int

getPHPCodeSnifferInstallPath()

Returns the path to the PHP_CodeSniffer package installation location

private getPHPCodeSnifferInstallPath() : string
Return values
string

getPHPCodeSnifferPackage()

Searches for the installed PHP_CodeSniffer Composer package

private getPHPCodeSnifferPackage([null|string|ConstraintInterface $versionConstraint = null ]) : PackageInterface|null
Parameters
$versionConstraint : null|string|ConstraintInterface = null

to match against

Return values
PackageInterface|null

getPHPCodingStandardPackages()

Iterates through Composers' local repository looking for valid Coding Standard packages.

private getPHPCodingStandardPackages() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Composer packages containing coding standard(s)

init()

Prepares the plugin so it's main functionality can be run.

private init() : mixed
Tags
throws
RuntimeException
LogicException
ProcessFailedException
RuntimeException

isPHPCodeSnifferInstalled()

Simple check if PHP_CodeSniffer is installed.

private isPHPCodeSnifferInstalled([null|string|ConstraintInterface $versionConstraint = null ]) : bool
Parameters
$versionConstraint : null|string|ConstraintInterface = null

to match against

Return values
bool —

Whether PHP_CodeSniffer is installed

isRunningGlobally()

Test if composer is running "global" This check kinda dirty, but it is the "Composer Way"

private isRunningGlobally() : bool
Tags
throws
RuntimeException
Return values
bool —

Whether Composer is running "globally"

loadInstalledPaths()

Load all paths from PHP_CodeSniffer into an array.

private loadInstalledPaths() : mixed
Tags
throws
LogicException
ProcessFailedException
RuntimeException

saveInstalledPaths()

Save all coding standard paths back into PHP_CodeSniffer

private saveInstalledPaths() : int
Tags
throws
LogicException
ProcessFailedException
RuntimeException
Return values
int —

Exit code. 0 for success, 1 or higher for failure.

updateInstalledPaths()

Check all installed packages (including the root package) against the installed paths from PHP_CodeSniffer and add the missing ones.

private updateInstalledPaths() : bool
Tags
throws
InvalidArgumentException
RuntimeException
Return values
bool —

True if changes where made, false otherwise

verifySaveSuccess()

Verify that the paths which were expected to be saved, have been.

private verifySaveSuccess() : int
Return values
int —

Exit code. 0 for success, 1 for failure.

On this page

Search results