ToolCommands
extends AbstractCommands
in package
Generic tools.
Tags
Table of Contents
Methods
- composerLockCheck() : int
- Check if 'composer.lock' exists on the project root folder.
- fixPermissions() : int|CollectionBuilder
- Run script to fix permissions (experimental).
- formatBytes() : string
- Helper to convert bytes to human-readable unit.
- getCommitTokens() : array<string|int, mixed>
- Check the commit message for SKIPPING tokens.
- getConfigurationFile() : string
- Path to YAML configuration file containing command defaults.
- getDeploymentEnvironment() : string
- Returns the current environment based on env vars.
- getJson() : array<string|int, mixed>
- Returns the JSON parsed content.
- getPackageLatestVersion() : null|string
- Returns the latest version of given package.
- getPackagePropertyFromComposer() : false|mixed
- Helper to return a property from a package in the composer.lock file.
- getWorkingDir() : string
- Returns the current working directory.
- isPackageInstalled() : bool
- Helper to tell if package is installed.
- isWebsiteInstalled() : bool
- Check if the website is installed.
- optsReview() : int
- Check project's .opts.yml file for forbidden commands.
- parseOptsYml() : array<string|int, mixed>|false
- Returns the .opts.yml file content.
- toolkitCodeReview() : ResultData
- Execute all or specific tools for static testing.
- toolkitInstallDependencies() : int
- Install packages present in the .opts.yml file under extra_pkgs section.
- toolkitNotifications() : int
- Display Toolkit notifications.
- toolkitRequirements() : int
- Check the Toolkit Requirements.
- toolkitVendorList() : int
- Check 'Vendor' packages being monitored.
- toolkitVersion() : int
- Check the Toolkit version.
- getBin() : string
- Validate and return the path to given bin.
- getBinPath() : string
- Return the path to given bin.
- getConfigValue() : mixed|null
- Return the configuration value.
- getNodeBin() : string
- Validate and return the path to given bin from node packages.
- getNodeBinPath() : string
- Return the path to given bin from node packages.
- isJunit() : bool
- Check whether Junit option is being used, or env var is set.
- isSimulating() : bool
- Check if current command is being executed with option simulate.
- taskExecute() : CollectionBuilder
- Execute a command.
- taskProcess() : ReplaceBlock|CollectionBuilder
- Process the file.
- taskReplaceBlock() : ReplaceBlock|CollectionBuilder
- Replace block in a file.
Methods
composerLockCheck()
Check if 'composer.lock' exists on the project root folder.
public
composerLockCheck(ConsoleIO $io) : int
Parameters
- $io : ConsoleIO
Tags
Return values
intfixPermissions()
Run script to fix permissions (experimental).
public
fixPermissions([array<string|int, mixed> $options = ['drupal_path' => InputOption::VALUE_OPTIONAL, 'drupal_user' => InputOption::VALUE_OPTIONAL, 'httpd_group' => InputOption::VALUE_OPTIONAL] ]) : int|CollectionBuilder
Parameters
- $options : array<string|int, mixed> = ['drupal_path' => InputOption::VALUE_OPTIONAL, 'drupal_user' => InputOption::VALUE_OPTIONAL, 'httpd_group' => InputOption::VALUE_OPTIONAL]
-
Command options.
Tags
Return values
int|CollectionBuilder —The fix permissions command task status.
formatBytes()
Helper to convert bytes to human-readable unit.
public
static formatBytes(int $bytes[, int $precision = 2 ]) : string
Parameters
- $bytes : int
-
The bytes to convert.
- $precision : int = 2
-
The precision for the conversion.
Return values
string —The converted value.
getCommitTokens()
Check the commit message for SKIPPING tokens.
public
static getCommitTokens() : array<string|int, mixed>
Return values
array<string|int, mixed> —An array with tokens present in the commit message.
getConfigurationFile()
Path to YAML configuration file containing command defaults.
public
getConfigurationFile() : string
Return values
string —Configuration file path.
getDeploymentEnvironment()
Returns the current environment based on env vars.
public
static getDeploymentEnvironment() : string
This command is called during build-dist, the build-dist is called in the create-distribution step during deployments. If CI env var is defined and TAG is available then the environment is 'prod' otherwise is 'acc'. If no CI env var is defined assume 'dev' environment.
Return values
string —The current environment, one of: 'dev', 'acc', 'prod'.
getJson()
Returns the JSON parsed content.
public
getJson(string $filename[, bool $throwException = true ]) : array<string|int, mixed>
Parameters
- $filename : string
- $throwException : bool = true
-
If the file is not found.
Return values
array<string|int, mixed> —Json parsed content.
getPackageLatestVersion()
Returns the latest version of given package.
public
static getPackageLatestVersion(string $package) : null|string
Parameters
- $package : string
-
The package to get the latest version, i.e: ec-europa/toolkit.
Return values
null|string —Returns the package version, or null if the package is not found.
getPackagePropertyFromComposer()
Helper to return a property from a package in the composer.lock file.
public
static getPackagePropertyFromComposer(string $package[, string $prop = 'version' ][, string|null $section = null ]) : false|mixed
Parameters
- $package : string
-
The package name to search.
- $prop : string = 'version'
-
The property to return, default to 'version'.
- $section : string|null = null
-
Set to 'packages' or 'packages-dev' to filter by section.
Tags
Return values
false|mixed —The property value, false if not found.
getWorkingDir()
Returns the current working directory.
public
getWorkingDir() : string
Return values
string —The current working directory.
isPackageInstalled()
Helper to tell if package is installed.
public
static isPackageInstalled(string $package) : bool
Parameters
- $package : string
-
The package name to search.
Return values
bool —True or false if not found.
isWebsiteInstalled()
Check if the website is installed.
public
isWebsiteInstalled() : bool
Return values
booloptsReview()
Check project's .opts.yml file for forbidden commands.
public
optsReview(ConsoleIO $io[, array<string|int, mixed> $options = ['endpoint' => InputOption::VALUE_REQUIRED] ]) : int
Parameters
- $io : ConsoleIO
- $options : array<string|int, mixed> = ['endpoint' => InputOption::VALUE_REQUIRED]
-
Command options.
Tags
Return values
int —The opts-review command status.
parseOptsYml()
Returns the .opts.yml file content.
public
static parseOptsYml() : array<string|int, mixed>|false
Tags
Return values
array<string|int, mixed>|false —An array with the content or false if the file do not exist.
toolkitCodeReview()
Execute all or specific tools for static testing.
public
toolkitCodeReview(ConsoleIO $io[, array<string|int, mixed> $options = ['phpcs' => InputOption::VALUE_NONE, 'opts-review' => InputOption::VALUE_NONE, 'lint-php' => InputOption::VALUE_NONE, 'lint-yaml' => InputOption::VALUE_NONE, 'lint-js' => InputOption::VALUE_NONE, 'phpstan' => InputOption::VALUE_NONE, 'phpmd' => InputOption::VALUE_NONE, 'phpunit' => InputOption::VALUE_NONE] ]) : ResultData
If no option is given, all the tests will be executed.
Parameters
- $io : ConsoleIO
- $options : array<string|int, mixed> = ['phpcs' => InputOption::VALUE_NONE, 'opts-review' => InputOption::VALUE_NONE, 'lint-php' => InputOption::VALUE_NONE, 'lint-yaml' => InputOption::VALUE_NONE, 'lint-js' => InputOption::VALUE_NONE, 'phpstan' => InputOption::VALUE_NONE, 'phpmd' => InputOption::VALUE_NONE, 'phpunit' => InputOption::VALUE_NONE]
-
Command options.
Tags
Return values
ResultData —The toolkit code-review command status.
toolkitInstallDependencies()
Install packages present in the .opts.yml file under extra_pkgs section.
public
toolkitInstallDependencies(ConsoleIO $io[, array<string|int, mixed> $options = ['packages' => InputOption::VALUE_REQUIRED, 'print' => InputOption::VALUE_NONE] ]) : int
Parameters
- $io : ConsoleIO
- $options : array<string|int, mixed> = ['packages' => InputOption::VALUE_REQUIRED, 'print' => InputOption::VALUE_NONE]
-
Command options.
Tags
Return values
int —The toolkit install-dependencies command status.
toolkitNotifications()
Display Toolkit notifications.
public
toolkitNotifications(ConsoleIO $io[, array<string|int, mixed> $options = ['endpoint' => InputOption::VALUE_OPTIONAL] ]) : int
Parameters
- $io : ConsoleIO
- $options : array<string|int, mixed> = ['endpoint' => InputOption::VALUE_OPTIONAL]
-
Command options.
Tags
Return values
int —The toolkit notifications command status.
toolkitRequirements()
Check the Toolkit Requirements.
public
toolkitRequirements(ConsoleIO $io[, array<string|int, mixed> $options = ['endpoint' => InputOption::VALUE_REQUIRED] ]) : int
Parameters
- $io : ConsoleIO
- $options : array<string|int, mixed> = ['endpoint' => InputOption::VALUE_REQUIRED]
-
Command options.
Tags
Return values
int —The toolkit requirements command status.
toolkitVendorList()
Check 'Vendor' packages being monitored.
public
toolkitVendorList(ConsoleIO $io) : int
Parameters
- $io : ConsoleIO
Tags
Return values
int —The toolkit vendor list command status.
toolkitVersion()
Check the Toolkit version.
public
toolkitVersion(ConsoleIO $io) : int
Parameters
- $io : ConsoleIO
Tags
Return values
int —The toolkit version command status.
getBin()
Validate and return the path to given bin.
protected
getBin(string $name) : string
Parameters
- $name : string
-
The bin to look for.
Tags
Return values
string —The bin path.
getBinPath()
Return the path to given bin.
protected
getBinPath(string $name) : string
Parameters
- $name : string
Return values
string —The path to given binary.
getConfigValue()
Return the configuration value.
protected
getConfigValue(string $key[, mixed|null $default = null ]) : mixed|null
Parameters
- $key : string
-
The config item to look up.
- $default : mixed|null = null
-
Default configuration value for the key item if neither has value nor exists.
Return values
mixed|null —The configuration value.
getNodeBin()
Validate and return the path to given bin from node packages.
protected
getNodeBin(string $name) : string
Parameters
- $name : string
-
The bin to look for.
Tags
Return values
string —The bin path.
getNodeBinPath()
Return the path to given bin from node packages.
protected
getNodeBinPath(string $name) : string
Parameters
- $name : string
Return values
string —The path to given binary.
isJunit()
Check whether Junit option is being used, or env var is set.
protected
isJunit() : bool
Return values
boolisSimulating()
Check if current command is being executed with option simulate.
protected
isSimulating() : bool
Return values
bool —True if using --simulate, false otherwise.
taskExecute()
Execute a command.
protected
taskExecute(array<string|int, string> $tasks) : CollectionBuilder
Parameters
- $tasks : array<string|int, string>
-
An array with tasks to execute.
Return values
CollectionBuilder —The task executed.
taskProcess()
Process the file.
protected
taskProcess(string $source[, string $destination = '' ]) : ReplaceBlock|CollectionBuilder
Parameters
- $source : string
-
The source file to process.
- $destination : string = ''
-
The destination file.
Return values
ReplaceBlock|CollectionBuilder —The file task processed.
taskReplaceBlock()
Replace block in a file.
protected
taskReplaceBlock([string $filename = '' ]) : ReplaceBlock|CollectionBuilder
Parameters
- $filename : string = ''
-
The file to process.
Return values
ReplaceBlock|CollectionBuilder —The file replaced.