diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 2877304..218fcb7 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -19,6 +19,6 @@ var/ vendor/ - + diff --git a/settings/site/default.local.settings.php b/settings/site/default.local.settings.php index 0ff57b7..b5a27b3 100644 --- a/settings/site/default.local.settings.php +++ b/settings/site/default.local.settings.php @@ -6,7 +6,6 @@ */ use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector; -use Drupal\Component\Assertion\Handle; $db_name = '${drupal.db.database}'; diff --git a/src/Common/Executor.php b/src/Common/Executor.php index cdde858..e4c1e2e 100644 --- a/src/Common/Executor.php +++ b/src/Common/Executor.php @@ -2,14 +2,17 @@ namespace Acquia\Drupal\RecommendedSettings\Common; +use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait; use GuzzleHttp\Client; use Psr\Log\LoggerAwareInterface; use Psr\Log\LoggerAwareTrait; use Robo\Collection\CollectionBuilder; +use Robo\Common\ProcessExecutor; use Robo\Contract\ConfigAwareInterface; -use Robo\Contract\IOAwareInterface; use Robo\Robo; +use Robo\Task\Base\Exec; +use Robo\Tasks; use Symfony\Component\Process\Process; /** @@ -26,13 +29,13 @@ class Executor implements ConfigAwareInterface, LoggerAwareInterface { /** * A copy of the Robo builder. * - * @var \Acquia\Blt\Robo\BltTasks*/ - protected $builder; + */ + protected \Robo\Tasks $builder; /** * Executor constructor. * - * @param \Robo\Collection\CollectionBuilder $builder + * @param \Robo\Tasks $builder * This is a copy of the collection builder, required for calling various * Robo tasks from non-command files. */ @@ -43,10 +46,10 @@ public function __construct(CollectionBuilder $builder) { /** * Returns $this->builder. * - * @return \Acquia\Blt\Robo\BltTasks + * @return \Robo\Tasks * The builder. */ - public function getBuilder() { + public function getBuilder(): Tasks { return $this->builder; } @@ -60,7 +63,7 @@ public function getBuilder() { * @return \Robo\Task\Base\Exec * The task. You must call run() on this to execute it! */ - public function taskExec($command) { + public function taskExec(string $command): Exec { return $this->builder->taskExec($command); } @@ -73,7 +76,7 @@ public function taskExec($command) { * @return \Robo\Common\ProcessExecutor * The unexecuted process. */ - public function drush($command) { + public function drush(mixed $command): ProcessExecutor { $drush_array = []; // @todo Set to silent if verbosity is less than very verbose. $drush_array[] = $this->getConfigValue('composer.bin') . DIRECTORY_SEPARATOR . "drush"; @@ -108,7 +111,7 @@ public function drush($command) { * @return \Robo\Common\ProcessExecutor * The unexecuted command. */ - public function execute($command) { + public function execute(mixed $command): ProcessExecutor { // Backwards compatibility check for legacy commands. if (!is_array($command)) { $this->say($command); @@ -132,7 +135,7 @@ public function execute($command) { * @return \Robo\Common\ProcessExecutor * The unexecuted command. */ - public function executeShell($command) { + public function executeShell(string $command): ProcessExecutor { $process_executor = Robo::process(Process::fromShellCommandline($command)); return $process_executor->dir($this->getConfigValue('repo.root')) ->printOutput(FALSE) @@ -146,7 +149,7 @@ public function executeShell($command) { * @param string $port * The port number. */ - public function killProcessByPort($port) { + public function killProcessByPort(string $port): void { $this->logger->info("Killing all processes on port '$port'..."); // This is allowed to fail. // @todo Replace with standardized call to Symfony Process. @@ -162,7 +165,7 @@ public function killProcessByPort($port) { * @param string $name * The name of the process. */ - public function killProcessByName($name) { + public function killProcessByName(string $name): void { $this->logger->info("Killing all processing containing string '$name'..."); // This is allowed to fail. // @todo Replace with standardized call to Symfony Process. @@ -179,7 +182,7 @@ public function killProcessByName($name) { * @param string $url * The URL to wait for. */ - public function waitForUrlAvailable($url) { + public function waitForUrlAvailable(string $url): void { $this->wait([$this, 'checkUrl'], [$url], "Waiting for non-50x response from $url..."); } @@ -190,7 +193,7 @@ public function waitForUrlAvailable($url) { * * @param callable $callable * The method/function to wait for a TRUE response from. - * @param array $args + * @param string[] $args * Arguments to pass to $callable. * @param string $message * The message to display when this function is called. @@ -200,7 +203,7 @@ public function waitForUrlAvailable($url) { * * @throws \Exception */ - public function wait(callable $callable, array $args, $message = '') { + public function wait(callable $callable, array $args, string $message = ''): bool { $maxWait = 60 * 1000; $checkEvery = 1 * 1000; $start = microtime(TRUE) * 1000; @@ -225,7 +228,7 @@ public function wait(callable $callable, array $args, $message = '') { usleep($checkEvery * 1000); } - throw new BltException("Timed out."); + throw new SettingsException("Timed out."); } /** @@ -237,7 +240,7 @@ public function wait(callable $callable, array $args, $message = '') { * @return bool * TRUE if URL responded with a non-50x response. */ - public function checkUrl($url) { + public function checkUrl(string $url): bool { try { $client = new Client(); $res = $client->request('GET', $url, [ diff --git a/src/Common/IO.php b/src/Common/IO.php index 074b26c..03a7102 100644 --- a/src/Common/IO.php +++ b/src/Common/IO.php @@ -18,7 +18,7 @@ trait IO { * @param string $text * The text to write. */ - protected function say($text) { + protected function say(string $text): void { $this->writeln($text); } @@ -32,7 +32,7 @@ protected function say($text) { * @param string $color * The color of the text. */ - protected function yell($text, $length = 40, $color = 'green') { + protected function yell(string $text, int $length = 40, string $color = 'green'): void { $format = "%s"; $this->formattedOutput($text, $length, $format); } @@ -46,7 +46,7 @@ protected function yell($text, $length = 40, $color = 'green') { * @return string * The formatted question text. */ - protected function formatQuestion($message) { + protected function formatQuestion(string $message): string { return " $message "; } @@ -55,7 +55,7 @@ protected function formatQuestion($message) { * * @param string $question * The question text. - * @param array $options + * @param string[] $options * An array of available options. * @param mixed $default * Default. @@ -63,7 +63,7 @@ protected function formatQuestion($message) { * @return string * The chosen option. */ - protected function askChoice($question, array $options, $default = NULL) { + protected function askChoice(string $question, array $options, mixed $default = NULL): string { return $this->doAsk(new ChoiceQuestion($this->formatQuestion($question), $options, $default)); } @@ -77,7 +77,7 @@ protected function askChoice($question, array $options, $default = NULL) { * @return string * The response. */ - protected function askRequired($message) { + protected function askRequired(string $message): string { $question = new Question($this->formatQuestion($message)); $question->setValidator(function ($answer) { if (empty($answer)) { @@ -94,15 +94,15 @@ protected function askRequired($message) { /** * Writes an array to the screen as a formatted table. * - * @param array $array + * @param string[] $array * The unformatted array. - * @param array $headers + * @param string[] $headers * The headers for the array. Defaults to ['Property','Value']. */ protected function printArrayAsTable( array $array, array $headers = ['Property', 'Value'] - ) { + ): void { $table = new Table($this->output); $table->setHeaders($headers) ->setRows(ArrayManipulator::convertArrayToFlatTextArray($array)) @@ -112,14 +112,14 @@ protected function printArrayAsTable( /** * Writes a particular configuration key's value to the log. * - * @param array $array + * @param string[] $array * The configuration. * @param string $prefix * A prefix to add to each row in the configuration. * @param int $verbosity * The verbosity level at which to display the logged message. */ - protected function logConfig(array $array, $prefix = '', $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE) { + protected function logConfig(array $array, string $prefix = '', int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): void { if ($this->output()->getVerbosity() >= $verbosity) { if ($prefix) { $this->output()->writeln("Configuration for $prefix:"); diff --git a/src/Common/StringManipulator.php b/src/Common/StringManipulator.php index d06c172..443fbd8 100644 --- a/src/Common/StringManipulator.php +++ b/src/Common/StringManipulator.php @@ -18,7 +18,7 @@ class StringManipulator { * @return string * The trimmed text. */ - public static function trimEndingLines($text, $num_lines) { + public static function trimEndingLines(string $text, int $num_lines): string { return implode("\n", array_slice(explode("\n", $text), 0, count($text) - $num_lines)); } @@ -34,7 +34,7 @@ public static function trimEndingLines($text, $num_lines) { * @return string * The trimmed text. */ - public static function trimStartingLines($text, $num_lines) { + public static function trimStartingLines(string $text, int $num_lines): string { return implode("\n", array_slice(explode("\n", $text), $num_lines)); } @@ -43,19 +43,19 @@ public static function trimStartingLines($text, $num_lines) { * * @param string $identifier * Identifier. - * @param array $filter + * @param string[] $filter * Filter. * * @return mixed * Safe string. */ - public static function convertStringToMachineSafe($identifier, array $filter = [ + public static function convertStringToMachineSafe(string $identifier, array $filter = [ ' ' => '_', '-' => '_', '/' => '_', '[' => '_', ']' => '', - ]) { + ]): mixed { $identifier = str_replace(array_keys($filter), array_values($filter), $identifier); // Valid characters are: // - a-z (U+0030 - U+0039) @@ -86,7 +86,7 @@ public static function convertStringToMachineSafe($identifier, array $filter = [ * @return mixed * Prefix. */ - public static function convertStringToPrefix($string) { + public static function convertStringToPrefix(string $string): mixed { $words = explode(' ', $string); $prefix = ''; foreach ($words as $word) { @@ -101,10 +101,10 @@ public static function convertStringToPrefix($string) { * @param string $command * The command string to conver to array. * - * @return array + * @return string[] * Command array. */ - public static function commandConvert($command) { + public static function commandConvert(string $command): array { return explode(" ", $command); } @@ -114,7 +114,7 @@ public static function commandConvert($command) { * @return string * The deprecation warning. */ - public static function stringToArrayMsg() { + public static function stringToArrayMsg(): string { return "Deprecation Warning: this command is passing a command string and should pass a command array."; } diff --git a/src/Config/DefaultConfig.php b/src/Config/DefaultConfig.php index 14b838d..bf9f0d6 100644 --- a/src/Config/DefaultConfig.php +++ b/src/Config/DefaultConfig.php @@ -3,8 +3,6 @@ namespace Acquia\Drupal\RecommendedSettings\Config; use Consolidation\Config\Config; -use Grasmash\YamlExpander\YamlExpander; -use Psr\Log\NullLogger; /** * The configuration for settings. diff --git a/src/Config/DefaultDrushConfig.php b/src/Config/DefaultDrushConfig.php index d4e4db0..637eca7 100644 --- a/src/Config/DefaultDrushConfig.php +++ b/src/Config/DefaultDrushConfig.php @@ -4,8 +4,6 @@ use Consolidation\Config\Config; use Drush\Config\DrushConfig; -use Grasmash\YamlExpander\YamlExpander; -use Psr\Log\NullLogger; /** * The configuration for settings. @@ -24,7 +22,7 @@ public function __construct(DrushConfig $config) { $config->set('docroot', $config->get("options.root")); $config->set('composer.bin', $config->get("drush.vendor-dir") . '/bin'); $config->set('drush.uri', $config->get("options.uri")); - $config->set('site', $config->get("options.uri")); + $config->set('site', $config->get("options.uri")); if ($config->get("options.ansi")) { $config->set('drush.ansi', $config->get("options.ansi")); } diff --git a/src/Drush/Commands/BaseDrushCommands.php b/src/Drush/Commands/BaseDrushCommands.php index 3efb29f..cd921df 100644 --- a/src/Drush/Commands/BaseDrushCommands.php +++ b/src/Drush/Commands/BaseDrushCommands.php @@ -7,9 +7,7 @@ use Acquia\Drupal\RecommendedSettings\Common\IO; use Acquia\Drupal\RecommendedSettings\Config\ConfigInitializer; use Acquia\Drupal\RecommendedSettings\Config\DefaultDrushConfig; -use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait; -use Acquia\Drupal\RecommendedSettings\Robo\Tasks\DrushTask; use Acquia\Drupal\RecommendedSettings\Robo\Tasks\LoadTasks; use Consolidation\AnnotatedCommand\AnnotationData; use Consolidation\AnnotatedCommand\Hooks\HookManager; @@ -52,12 +50,12 @@ public function init(InputInterface $input, AnnotationData $annotationData): voi /** * Invokes an array of Drush commands. * - * @param array $commands + * @param string[] $commands * An array of Symfony commands to invoke, e.g., 'tests:behat:run'. * * @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException */ - protected function invokeCommands(array $commands) { + protected function invokeCommands(array $commands): void { foreach ($commands as $key => $value) { if (is_numeric($key)) { $command = $value; @@ -76,7 +74,7 @@ protected function invokeCommands(array $commands) { * * @param string $command_name * The name of the command, e.g., 'status'. - * @param array $args + * @param string[] $args * An array of arguments to pass to the command. * * @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException @@ -90,15 +88,15 @@ protected function invokeCommand(string $command_name, array $args = []): void { } } $process = Drush::drush(Drush::aliasManager()->getSelf(), $command_name, $args, $options); - $this->output->writeln(" > " . $command_name. ""); + $this->output->writeln(" > " . $command_name . ""); $output = $this->output(); $process->setTty(Process::isTtySupported()); - $process->run(static function ($type, $buffer) use ($output, $process) { + $process->run(static function ($type, $buffer) use ($output, $process): void { if (Process::ERR === $type) { - $output->getErrorOutput()->write($buffer, false, OutputInterface::OUTPUT_NORMAL); + $output->getErrorOutput()->write($buffer, FALSE, OutputInterface::OUTPUT_NORMAL); } else { - $output->write($buffer, false, OutputInterface::OUTPUT_NORMAL); + $output->write($buffer, FALSE, OutputInterface::OUTPUT_NORMAL); } }); } diff --git a/src/Drush/Commands/HooksDrushCommands.php b/src/Drush/Commands/HooksDrushCommands.php index 3832e51..7abe043 100644 --- a/src/Drush/Commands/HooksDrushCommands.php +++ b/src/Drush/Commands/HooksDrushCommands.php @@ -5,9 +5,6 @@ namespace Acquia\Drupal\RecommendedSettings\Drush\Commands; use Acquia\Drupal\RecommendedSettings\Helpers\EnvironmentDetector; -use Consolidation\AnnotatedCommand\CommandData; -use Consolidation\AnnotatedCommand\Events\CustomEventAwareInterface; -use Consolidation\AnnotatedCommand\Events\CustomEventAwareTrait; use Consolidation\AnnotatedCommand\Hooks\HookManager; use Drush\Attributes as CLI; use Drush\Commands\DrushCommands; diff --git a/src/Drush/Commands/MultisiteDrushCommands.php b/src/Drush/Commands/MultisiteDrushCommands.php index ca7c123..a1045c0 100644 --- a/src/Drush/Commands/MultisiteDrushCommands.php +++ b/src/Drush/Commands/MultisiteDrushCommands.php @@ -16,9 +16,7 @@ use Drush\Boot\BootstrapManager; use Drush\Boot\DrupalBootLevels; use Drush\Commands\DrushCommands; -use Drush\Drush; use Psr\Container\ContainerInterface as DrushContainer; -use Symfony\Component\Filesystem\Path; /** * A Drush command to generate settings.php for Multisite. @@ -127,13 +125,14 @@ protected function postGenerateSettings(CommandData $commandData): void { * * @param string $site_name * The site name. - * - * @return array + * @param string[] $default_credentials + * The default db credentials. + * @return string[] * The database specs. */ - private function askDbCredentials(string $site_name, array $defaultCredentials): array { + private function askDbCredentials(string $site_name, array $default_credentials): array { $shouldAsk = $this->io()->confirm(dt("Would you like to configure the local database credentials?")); - $credentials = $defaultCredentials; + $credentials = $default_credentials; if ($shouldAsk) { $credentials['database'] = $this->io()->ask("Local database name", $site_name); $credentials['username'] = $this->io()->ask("Local database user", $credentials['username']); diff --git a/src/Drush/Traits/SiteUriTrait.php b/src/Drush/Traits/SiteUriTrait.php index f9f26a6..6f5115f 100644 --- a/src/Drush/Traits/SiteUriTrait.php +++ b/src/Drush/Traits/SiteUriTrait.php @@ -16,10 +16,15 @@ trait SiteUriTrait { * * This code copied from SiteInstallCommands.php file. * + * @param string $root + * The path to drupal docroot. + * @param string $uri + * The site uri. + * * @return array|false|mixed|string|string[] * Returns the site uri. */ - private function getSitesSubdirFromUri($root, $uri): mixed { + private function getSitesSubdirFromUri(string $root, string $uri): mixed { $dir = strtolower($uri); // Always accept simple uris (e.g. 'dev', 'stage', etc.) if (preg_match('#^[a-z0-9_-]*$#', $dir)) { diff --git a/src/Robo/Config/ConfigAwareTrait.php b/src/Robo/Config/ConfigAwareTrait.php index 8f7436f..c03386e 100644 --- a/src/Robo/Config/ConfigAwareTrait.php +++ b/src/Robo/Config/ConfigAwareTrait.php @@ -22,7 +22,7 @@ trait ConfigAwareTrait { * @return mixed|null * The config value, or else the default value if they key does not exist. */ - protected function getConfigValue($key, $default = NULL) { + protected function getConfigValue(string $key, mixed $default = NULL): mixed { if (!$this->getConfig()) { return $default; } diff --git a/src/Robo/Inspector/Inspector.php b/src/Robo/Inspector/Inspector.php index fe92a2e..dc596b0 100644 --- a/src/Robo/Inspector/Inspector.php +++ b/src/Robo/Inspector/Inspector.php @@ -12,7 +12,6 @@ use Acquia\Drupal\RecommendedSettings\Common\IO; use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; use Acquia\Drupal\RecommendedSettings\Robo\Config\ConfigAwareTrait; -use Consolidation\Config\Loader\YamlConfigLoader; use League\Container\ContainerAwareInterface; use League\Container\ContainerAwareTrait; use Psr\Log\LoggerAwareInterface; @@ -25,7 +24,7 @@ /** * Inspects various details about the current project. * - * @package Acquia\Blt\Robo\Common + * @package Acquia\Drupal\RecommendedSettings\Common */ class Inspector implements BuilderAwareInterface, ConfigAwareInterface, ContainerAwareInterface, LoggerAwareInterface { @@ -38,56 +37,44 @@ class Inspector implements BuilderAwareInterface, ConfigAwareInterface, Containe /** * Process executor. * - * @var \Acquia\Blt\Robo\Common\Executor */ - protected $executor; + protected \Acquia\Drupal\RecommendedSettings\Common\Executor $executor; /** * Is MYSQL available. * - * @var null */ - protected $isMySqlAvailable = NULL; + protected bool $isMySqlAvailable; /** * Is PostgreSQL available. * - * @var null */ - protected $isPostgreSqlAvailable = NULL; + protected bool $isPostgreSqlAvailable; /** * Is Sqlite available. * - * @var null */ - protected $isSqliteAvailable = NULL; + protected bool $isSqliteAvailable; - /** - * DrupalVM status. - * - * @var array - */ - protected $drupalVmStatus = NULL; /** * Filesystem. * - * @var \Symfony\Component\Filesystem\Filesystem */ - protected $fs; + protected \Symfony\Component\Filesystem\Filesystem $fs; /** * Warnings were issued. * - * @var bool */ - protected $warningsIssued = FALSE; + protected bool $warningsIssued = FALSE; /** * The constructor. * - * @param \Acquia\Blt\Robo\Common\Executor $executor + * @param \Acquia\Drupal\RecommendedSettings\Common\Executor $executor * Process executor. */ public function __construct(Executor $executor) { @@ -101,14 +88,14 @@ public function __construct(Executor $executor) { * @return \Symfony\Component\Filesystem\Filesystem * Filesystem. */ - public function getFs() { + public function getFs(): \Symfony\Component\Filesystem\Filesystem { return $this->fs; } /** * Clear state. */ - public function clearState() { + public function clearState(): void { $this->isMySqlAvailable = NULL; $this->isPostgreSqlAvailable = NULL; $this->isSqliteAvailable = NULL; @@ -120,7 +107,7 @@ public function clearState() { * @return bool * TRUE if file exists. */ - public function isRepoRootPresent() { + public function isRepoRootPresent(): bool { return file_exists($this->getConfigValue('repo.root')); } @@ -130,7 +117,7 @@ public function isRepoRootPresent() { * @return bool * TRUE if file exists. */ - public function isDocrootPresent() { + public function isDocrootPresent(): bool { return file_exists($this->getConfigValue('docroot')); } @@ -140,7 +127,7 @@ public function isDocrootPresent() { * @return bool * TRUE if file exists. */ - public function isDrupalSettingsFilePresent() { + public function isDrupalSettingsFilePresent(): bool { return file_exists($this->getConfigValue('drupal.settings_file')); } @@ -150,7 +137,7 @@ public function isDrupalSettingsFilePresent() { * @return bool * TRUE if file exists. */ - public function isHashSaltPresent() { + public function isHashSaltPresent(): bool { return file_exists($this->getConfigValue('repo.root') . '/salt.txt'); } @@ -160,17 +147,17 @@ public function isHashSaltPresent() { * @return bool * TRUE if file exists. */ - public function isDrupalLocalSettingsFilePresent() { + public function isDrupalLocalSettingsFilePresent(): bool { return file_exists($this->getConfigValue('drupal.local_settings_file')); } /** - * Determines if Drupal settings.php contains required BLT includes. + * Determines if Drupal settings.php contains required DRS includes. * * @return bool - * TRUE if settings.php is valid for BLT usage. + * TRUE if settings.php is valid for DRS usage. */ - public function isDrupalSettingsFileValid() { + public function isDrupalSettingsFileValid(): bool { $settings_file_contents = file_get_contents($this->getConfigValue('drupal.settings_file')); if (!strstr($settings_file_contents, '/../vendor/acquia/blt/settings/blt.settings.php') @@ -189,7 +176,7 @@ public function isDrupalSettingsFileValid() { * @return bool * TRUE if Drupal is installed. */ - public function isDrupalInstalled() { + public function isDrupalInstalled(): bool { $this->logger->debug("Verifying that Drupal is installed..."); $output = $this->getDrushStatus()['bootstrap'] ?? ''; $installed = $output === 'Successful'; @@ -201,10 +188,10 @@ public function isDrupalInstalled() { /** * Gets the result of `drush status`. * - * @return array + * @return string[] * The result of `drush status`. */ - public function getDrushStatus() { + public function getDrushStatus(): array { $docroot = $this->getConfigValue('docroot'); $status_info = (array) json_decode($this->executor->drush([ 'status', @@ -222,7 +209,7 @@ public function getDrushStatus() { * @return mixed * Status. */ - public function getStatus() { + public function getStatus(): mixed { $status = $this->getDrushStatus(); if (array_key_exists('php-conf', $status)) { foreach ($status['php-conf'] as $key => $conf) { @@ -258,7 +245,7 @@ public function getStatus() { * @return bool * TRUE if alias is valid. */ - public function isDrushAliasValid($alias) { + public function isDrushAliasValid(string $alias): bool { return $this->executor->drush([ "site:alias", "@$alias", @@ -274,7 +261,7 @@ public function isDrushAliasValid($alias) { * @return bool * TRUE if MySQL is available. */ - public function isDatabaseAvailable() { + public function isDatabaseAvailable(): bool { $db = $this->getDrushStatus()['db-driver']; switch ($db) { case 'mysql': @@ -286,7 +273,7 @@ public function isDatabaseAvailable() { case 'sqlite': return $this->isSqliteAvailable(); } - + return FALSE; } /** @@ -297,7 +284,7 @@ public function isDatabaseAvailable() { * @return bool * TRUE if MySQL is available. */ - public function isMySqlAvailable() { + public function isMySqlAvailable(): bool { if (is_null($this->isMySqlAvailable)) { $this->isMySqlAvailable = $this->getMySqlAvailable(); } @@ -313,7 +300,7 @@ public function isMySqlAvailable() { * @return bool * TRUE if MySQL is available. */ - public function getMySqlAvailable() { + public function getMySqlAvailable(): bool { $this->logger->debug("Verifying that MySQL is available..."); /** @var \Robo\Result $result */ $result = $this->executor->drush(["sqlq", "SHOW DATABASES"]) @@ -330,7 +317,7 @@ public function getMySqlAvailable() { * @return bool * TRUE if MySQL is available. */ - public function isPostgreSqlAvailable() { + public function isPostgreSqlAvailable(): bool { if (is_null($this->isPostgreSqlAvailable)) { $this->isPostgreSqlAvailable = $this->getPostgreSqlAvailable(); } @@ -346,7 +333,7 @@ public function isPostgreSqlAvailable() { * @return bool * TRUE if PostgreSQL is available. */ - public function getPostgreSqlAvailable() { + public function getPostgreSqlAvailable(): bool { $this->logger->debug("Verifying that PostgreSQL is available..."); /** @var \Robo\Result $result */ $result = $this->executor->drush(["sqlq \"SHOW DATABASES\""]) @@ -363,7 +350,7 @@ public function getPostgreSqlAvailable() { * @return bool * TRUE if Sqlite is available. */ - public function isSqliteAvailable() { + public function isSqliteAvailable(): bool { if (is_null($this->isSqliteAvailable)) { $this->isSqliteAvailable = $this->getSqliteAvailable(); } @@ -379,7 +366,7 @@ public function isSqliteAvailable() { * @return bool * TRUE if Sqlite is available. */ - public function getSqliteAvailable() { + public function getSqliteAvailable(): bool { $this->logger->debug("Verifying that Sqlite is available..."); /** @var \Robo\Result $result */ $result = $this->executor->drush(["sqlq", ".tables"]) @@ -394,7 +381,7 @@ public function getSqliteAvailable() { * @return bool * TRUE if Lando configuration exists. */ - public function isLandoConfigPresent() { + public function isLandoConfigPresent(): bool { return file_exists($this->getConfigValue('repo.root') . '/.lando.yml'); } @@ -404,7 +391,7 @@ public function isLandoConfigPresent() { * @return string * The version of Composer. */ - public function getComposerVersion() { + public function getComposerVersion(): string { $version = $this->executor->execute(["composer", "--version"]) ->interactive(FALSE) ->silent(TRUE) @@ -423,7 +410,7 @@ public function getComposerVersion() { * @return bool * TRUE if minimum version is satisfied. */ - public function isComposerMinimumVersionSatisfied($minimum_version) { + public function isComposerMinimumVersionSatisfied(string $minimum_version): bool { // phpcs:ignore exec("composer --version | cut -d' ' -f3", $output, $exit_code); if (version_compare($output[0], $minimum_version, '>=')) { @@ -441,7 +428,7 @@ public function isComposerMinimumVersionSatisfied($minimum_version) { * @return bool * TRUE if the command exists, otherwise FALSE. */ - public function commandExists($command) { + public function commandExists(string $command): bool { // phpcs:ignore exec("command -v $command >/dev/null 2>&1", $output, $exit_code); return $exit_code == 0; @@ -456,7 +443,7 @@ public function commandExists($command) { * @return bool * TRUE if minimum version is satisfied. */ - public function isGitMinimumVersionSatisfied($minimum_version) { + public function isGitMinimumVersionSatisfied(string $minimum_version): bool { // phpcs:ignore exec("git --version | cut -d' ' -f3", $output, $exit_code); if (version_compare($output[0], $minimum_version, '>=')) { @@ -471,7 +458,7 @@ public function isGitMinimumVersionSatisfied($minimum_version) { * @return bool * TRUE if configured, FALSE otherwise. */ - public function isGitUserSet() { + public function isGitUserSet(): bool { // phpcs:ignore exec("git config user.name", $output, $name_not_set); // phpcs:ignore @@ -485,18 +472,18 @@ public function isGitUserSet() { * @return \Acquia\Blt\Robo\Config\BltConfig * The local Behat configuration. */ -// public function getLocalBehatConfig() { -// $behat_local_config_file = $this->getConfigValue('repo.root') . '/tests/behat/local.yml'; -// -// $behat_local_config = new BltConfig(); -// $loader = new YamlConfigLoader(); -// $processor = new YamlConfigProcessor(); -// $processor->extend($loader->load($behat_local_config_file)); -// $processor->extend($loader->load($this->getConfigValue('repo.root') . '/tests/behat/behat.yml')); -// $behat_local_config->replace($processor->export()); -// -// return $behat_local_config; -// } + // public function getLocalBehatConfig() { + // $behat_local_config_file = $this->getConfigValue('repo.root') . '/tests/behat/local.yml'; + // + // $behat_local_config = new BltConfig(); + // $loader = new YamlConfigLoader(); + // $processor = new YamlConfigProcessor(); + // $processor->extend($loader->load($behat_local_config_file)); + // $processor->extend($loader->load($this->getConfigValue('repo.root') . '/tests/behat/behat.yml')); + // $behat_local_config->replace($processor->export()); + // + // return $behat_local_config; + // } /** * Returns an array of required Behat files, as defined by Behat config. @@ -505,10 +492,10 @@ public function isGitUserSet() { * and bootstrap dir on the local file system. All of these files are * required for behat to function properly. * - * @return array + * @return string[] * An array of required Behat configuration files. */ - public function getBehatConfigFiles() { + public function getBehatConfigFiles(): array { $behat_local_config = $this->getLocalBehatConfig(); return [ @@ -523,17 +510,20 @@ public function getBehatConfigFiles() { * @return bool * TRUE if all required Behat files exist. */ - public function areBehatConfigFilesPresent() { + public function areBehatConfigFilesPresent(): bool { return $this->filesExist($this->getBehatConfigFiles()); } /** * Determines if all file in a given array exist. * + * @param string[] $files + * An array of files. + * * @return bool * TRUE if all files exist. */ - public function filesExist($files) { + public function filesExist(array $files): bool { foreach ($files as $file) { if (!file_exists($file)) { $this->logger->warning("Required file $file does not exist."); @@ -550,7 +540,7 @@ public function filesExist($files) { * @return string * The current schema version. */ - public function getCurrentSchemaVersion() { + public function getCurrentSchemaVersion(): string { if (file_exists($this->getConfigValue('blt.config-files.schema-version'))) { $version = trim(file_get_contents($this->getConfigValue('blt.config-files.schema-version'))); } @@ -564,7 +554,7 @@ public function getCurrentSchemaVersion() { /** * Is schema version up to date? */ - public function isSchemaVersionUpToDate() { + public function isSchemaVersionUpToDate(): bool { return $this->getCurrentSchemaVersion() >= $this->getContainer()->get('updater')->getLatestUpdateMethodVersion(); } @@ -572,9 +562,9 @@ public function isSchemaVersionUpToDate() { * Issues warnings to user if their local environment is mis-configured. * * @param string $command_name - * The name of the BLT Command being executed. + * The name of the DRS Command being executed. */ - public function issueEnvironmentWarnings($command_name) { + public function issueEnvironmentWarnings(string $command_name): void { if (!$this->warningsIssued) { $this->warnIfPhpOutdated(); @@ -585,13 +575,13 @@ public function issueEnvironmentWarnings($command_name) { /** * Throws an exception if the minimum PHP version is not met. * - * @throws \Acquia\Blt\Robo\Exceptions\BltException + * @throws \Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException */ - public function warnIfPhpOutdated() { + public function warnIfPhpOutdated(): void { $minimum_php_version = 7; $current_php_version = phpversion(); if ($current_php_version < $minimum_php_version) { - throw new SettingsException("BLT requires PHP $minimum_php_version or greater. You are using $current_php_version."); + throw new SettingsException("DRS requires PHP $minimum_php_version or greater. You are using $current_php_version."); } } @@ -601,7 +591,7 @@ public function warnIfPhpOutdated() { * @return bool * TRUE if config is identical. */ - public function isActiveConfigIdentical() { + public function isActiveConfigIdentical(): bool { $result = $this->executor->drush(["config:status"])->run(); $message = trim($result->getMessage()); $this->logger->debug("Config status check results:"); diff --git a/src/Robo/Inspector/InspectorAwareInterface.php b/src/Robo/Inspector/InspectorAwareInterface.php index bad2540..f1e1e72 100644 --- a/src/Robo/Inspector/InspectorAwareInterface.php +++ b/src/Robo/Inspector/InspectorAwareInterface.php @@ -10,7 +10,7 @@ interface InspectorAwareInterface { /** * Sets $this->inspector. * - * @param \Acquia\Blt\Robo\Inspector\Inspector $inspector + * @param \Acquia\Drupal\RecommendedSettings\Robo\Inspector\Inspector $inspector * The inspector. * * @return $this diff --git a/src/Robo/Inspector/InspectorAwareTrait.php b/src/Robo/Inspector/InspectorAwareTrait.php index b5522f7..0f5fcb2 100644 --- a/src/Robo/Inspector/InspectorAwareTrait.php +++ b/src/Robo/Inspector/InspectorAwareTrait.php @@ -10,14 +10,13 @@ trait InspectorAwareTrait { /** * The inspector. * - * @var \Acquia\Blt\Robo\Inspector\Inspector */ - private $inspector; + private Inspector $inspector; /** * Sets $this->inspector. */ - public function setInspector(Inspector $inspector) { + public function setInspector(Inspector $inspector): self { $this->inspector = $inspector; return $this; @@ -26,10 +25,10 @@ public function setInspector(Inspector $inspector) { /** * Gets $this->inspector. * - * @return \Acquia\Blt\Robo\Inspector\Inspector + * @return \Acquia\Drupal\RecommendedSettings\Robo\Inspector\Inspector * The inspector. */ - public function getInspector() { + public function getInspector(): Inspector { return $this->inspector; } diff --git a/src/Robo/Tasks/DrushTask.php b/src/Robo/Tasks/DrushTask.php index 5ba6aef..045f85a 100644 --- a/src/Robo/Tasks/DrushTask.php +++ b/src/Robo/Tasks/DrushTask.php @@ -29,81 +29,72 @@ class DrushTask extends CommandStack { /** * Site alias to prepend to each command. * - * @var string */ - protected $alias; + protected string $alias; /** * Directory to execute the command from. * - * @var string * * @see ExecTrait::$workingDirectory */ - protected $dir; + protected string $dir; /** * Site uri to append uri option to each command. * - * @var string */ - protected $uri; + protected string $uri; /** * Indicates if the command output should be verbose. * - * @var bool */ - protected $verbose; + protected bool $verbose; /** * Indicates if the command output should be very verbose. * - * @var bool */ - protected $veryVerbose; + protected bool $veryVerbose; /** * Indicates if the command output should be debug verbosity. * - * @var bool */ - protected $debug; + protected bool $debug; /** * Defaults init. * - * @var bool */ - protected $defaultsInitialized; + protected bool $defaultsInitialized; /** * Additional directory paths to search for drush commands. * - * @var string */ - protected $include; + protected string $include; /** * Add or not the --ansi option. * - * @var bool */ - protected $ansi; + protected bool $ansi; /** * Drush commands to execute when task is run. * - * @var array + * @var string[] */ - protected $commands; + protected array $commands; /** * Options for each drush command. * - * @var array + * @var string[] */ - protected $options; + protected array $options; /** * Adds the given drush command to a stack. @@ -113,7 +104,7 @@ class DrushTask extends CommandStack { * * @return $this */ - public function drush($command) { + public function drush(string $command) { // Clear out options associated with previous drush command. $this->setOptionsForLastCommand(); @@ -137,7 +128,7 @@ public function drush($command) { * * @return $this */ - public function alias($alias) { + public function alias(string $alias) { $this->alias = $alias; return $this; } @@ -150,7 +141,7 @@ public function alias($alias) { * * @return $this */ - public function uri($uri) { + public function uri(string $uri) { $this->uri = $uri; return $this; @@ -166,7 +157,7 @@ public function uri($uri) { * * @see ExecTrait::$workingDirectory */ - public function dir($dir) { + public function dir(string $dir) { $this->dir = $dir; parent::dir($dir); @@ -181,7 +172,7 @@ public function dir($dir) { * * @return $this */ - public function verbose($verbose) { + public function verbose(string|bool $verbose) { $this->verbose = $this->mixedToBool($verbose); return $this; } @@ -194,7 +185,7 @@ public function verbose($verbose) { * * @return $this */ - public function veryVerbose($verbose) { + public function veryVerbose(string|bool $verbose) { $this->veryVerbose = $this->mixedToBool($verbose); return $this; } @@ -207,7 +198,7 @@ public function veryVerbose($verbose) { * * @return $this */ - public function debug($verbose) { + public function debug(string|bool $verbose) { $this->debug = $this->mixedToBool($verbose); return $this; } @@ -220,7 +211,7 @@ public function debug($verbose) { * * @return $this */ - public function includePath($path) { + public function includePath(string $path) { $this->include = $path; return $this; } @@ -233,7 +224,7 @@ public function includePath($path) { * * @return $this */ - public function ansi($ansi) { + public function ansi(bool $ansi) { $this->ansi = $ansi; return $this; } @@ -241,7 +232,7 @@ public function ansi($ansi) { /** * Sets up drush defaults using config. */ - protected function init() { + protected function init(): void { if ($this->getConfig()->get('drush.bin')) { $this->executable = str_replace(' ', '\\ ', $this->getConfig()->get('drush.bin')); } @@ -278,7 +269,7 @@ protected function init() { * TRUE/FALSE as per PHP's cast to boolean ruleset, with the exception that * a string value not equal to 'yes' or 'true' will evaluate to FALSE. */ - protected function mixedToBool($mixedVar) { + protected function mixedToBool(mixed $mixedVar): bool { if (is_string($mixedVar)) { $boolVar = ($mixedVar === 'yes' || $mixedVar === 'true'); } @@ -291,7 +282,7 @@ protected function mixedToBool($mixedVar) { /** * Associates arguments with their corresponding drush command. */ - protected function setOptionsForLastCommand() { + protected function setOptionsForLastCommand(): void { if (isset($this->commands)) { $numberOfCommands = count($this->commands); $correspondingCommand = $numberOfCommands - 1; @@ -306,7 +297,7 @@ protected function setOptionsForLastCommand() { /** * Set the options to be used for each drush command in the stack. */ - protected function setGlobalOptions() { + protected function setGlobalOptions(): void { if (isset($this->uri) && !empty($this->uri)) { $this->option('uri', $this->uri); } @@ -360,8 +351,17 @@ protected function setGlobalOptions() { /** * Overriding CommandArguments::option to default option separator to '='. + * + * @param string $option + * An option key. + * @param string $value + * Value for option. + * @param string $separator + * The separator for options. + * + * @return $this */ - public function option($option, $value = NULL, $separator = '=') { + public function option(string $option, string $value = NULL, string $separator = '=') { return $this->traitOption($option, $value, $separator); } @@ -370,6 +370,8 @@ public function option($option, $value = NULL, $separator = '=') { * * Make note that if stopOnFail() is TRUE, then result data isn't returned! * Maybe this should be changed. + * + * {@inheritdoc} */ public function run() { $this->setupExecution(); @@ -406,7 +408,7 @@ public function run() { /** * Adds drush commands with their corresponding options to stack. */ - protected function setupExecution() { + protected function setupExecution(): void { $this->setOptionsForLastCommand(); $this->setGlobalOptions(); diff --git a/src/Robo/Tasks/LoadTasks.php b/src/Robo/Tasks/LoadTasks.php index defe95b..b07895a 100644 --- a/src/Robo/Tasks/LoadTasks.php +++ b/src/Robo/Tasks/LoadTasks.php @@ -13,8 +13,8 @@ trait LoadTasks { * @return \Acquia\Drupal\RecommendedSettings\Robo\Tasks\DrushTask * Drush task. */ - protected function taskDrush() { - /** @var \Acquia\Blt\Robo\Tasks\DrushTask $task */ + protected function taskDrush(): DrushTask { + /** @var \Acquia\Drupal\RecommendedSettings\Robo\Tasks\DrushTask $task */ $task = $this->task(DrushTask::class); /** @var \Symfony\Component\Console\Output\OutputInterface $output */ $output = $this->output(); diff --git a/src/Settings.php b/src/Settings.php index 8becaea..ef3118c 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -7,7 +7,6 @@ use Acquia\Drupal\RecommendedSettings\Config\SettingsConfig; use Acquia\Drupal\RecommendedSettings\Exceptions\SettingsException; use Acquia\Drupal\RecommendedSettings\Helpers\Filesystem; -use Consolidation\Config\Config; /** * Core class of the plugin.