From 25e00e5a82d4cbe60ee5d89358f4ee4e415dc330 Mon Sep 17 00:00:00 2001 From: Moshe Weitzman Date: Fri, 26 Apr 2024 12:37:58 -0400 Subject: [PATCH] Some phpstan Level 1 fixes (#5973) --- .circleci/config.yml | 2 +- src/Commands/DrushCommands.php | 9 +++++++++ src/Commands/core/SiteInstallCommands.php | 7 ++++--- src/Commands/core/UserCommands.php | 8 ++++---- src/Commands/core/WatchdogCommands.php | 8 ++++---- src/Commands/pm/PmCommands.php | 4 ++-- src/Runtime/DependencyInjection.php | 2 +- src/Runtime/RedispatchHook.php | 2 +- src/Sql/SqlBase.php | 12 ++++++------ src/Utils/FsUtils.php | 18 ++++-------------- src/Utils/StringUtils.php | 2 +- 11 files changed, 37 insertions(+), 37 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index fa74214f0f..5574ea2ecd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,7 +76,7 @@ jobs: code_style: <<: *defaults docker: - - image: wodby/php:$WODBY_TAG + - image: wodby/php:8.2 steps: - checkout - run: cp .docker/zz-php.ini /usr/local/etc/php/conf.d/ diff --git a/src/Commands/DrushCommands.php b/src/Commands/DrushCommands.php index 348ccd1d17..c92751c5fa 100644 --- a/src/Commands/DrushCommands.php +++ b/src/Commands/DrushCommands.php @@ -14,6 +14,7 @@ use Drush\Drush; use Drush\Exec\ExecTrait; use Drush\Log\DrushLoggerManager; +use Drush\SiteAlias\ProcessManager; use Drush\Style\DrushStyle; use GuzzleHttp\HandlerStack; use GuzzleHttp\MessageFormatter; @@ -140,4 +141,12 @@ protected function getStack(): HandlerStack $stack->push(Middleware::log($this->logger(), new MessageFormatter(Drush::debug() ? MessageFormatter::DEBUG : MessageFormatter::SHORT))); return $stack; } + + /** + * This method overrides the trait in order to provide a more specific return type. + */ + public function processManager(): ProcessManager + { + return $this->processManager; + } } diff --git a/src/Commands/core/SiteInstallCommands.php b/src/Commands/core/SiteInstallCommands.php index 508e6c2980..24c9dd2247 100644 --- a/src/Commands/core/SiteInstallCommands.php +++ b/src/Commands/core/SiteInstallCommands.php @@ -423,7 +423,8 @@ public function pre(CommandData $commandData): void // Can't install without sites subdirectory and settings.php. if (!file_exists($confPath)) { - if ((new Filesystem())->mkdir($confPath) && !$this->config->simulate()) { + (new Filesystem())->mkdir($confPath); + if (!$this->getConfig()->simulate()) { throw new \Exception(dt('Failed to create directory @confPath', ['@confPath' => $confPath])); } } else { @@ -431,14 +432,14 @@ public function pre(CommandData $commandData): void } if (!drush_file_not_empty($settingsfile)) { - if (!drush_op('copy', 'sites/default/default.settings.php', $settingsfile) && !$this->config->simulate()) { + if (!drush_op('copy', 'sites/default/default.settings.php', $settingsfile) && !$this->getConfig()->simulate()) { throw new \Exception(dt('Failed to copy sites/default/default.settings.php to @settingsfile', ['@settingsfile' => $settingsfile])); } } // Write an empty sites.php if we using multi-site. if ($sitesfile_write) { - if (!drush_op('copy', 'sites/example.sites.php', $sitesfile) && !$this->config->simulate()) { + if (!drush_op('copy', 'sites/example.sites.php', $sitesfile) && !$this->getConfig()->simulate()) { throw new \Exception(dt('Failed to copy sites/example.sites.php to @sitesfile', ['@sitesfile' => $sitesfile])); } } diff --git a/src/Commands/core/UserCommands.php b/src/Commands/core/UserCommands.php index d1dd3e53af..4f3738da4a 100644 --- a/src/Commands/core/UserCommands.php +++ b/src/Commands/core/UserCommands.php @@ -134,7 +134,7 @@ public function block(string $names = '', $options = ['uid' => self::REQ, 'mail' foreach ($accounts as $id => $account) { $account->block(); $account->save(); - $this->logger->success(dt('Blocked user(s): !user', ['!user' => $account->getAccountName()])); + $this->logger()->success(dt('Blocked user(s): !user', ['!user' => $account->getAccountName()])); } } @@ -152,7 +152,7 @@ public function unblock(string $names = '', $options = ['uid' => self::REQ, 'mai foreach ($accounts as $id => $account) { $account->activate(); $account->save(); - $this->logger->success(dt('Unblocked user(s): !user', ['!user' => $account->getAccountName()])); + $this->logger()->success(dt('Unblocked user(s): !user', ['!user' => $account->getAccountName()])); } } @@ -173,7 +173,7 @@ public function addRole(string $role, string $names = '', $options = ['uid' => s foreach ($accounts as $id => $account) { $account->addRole($role); $account->save(); - $this->logger->success(dt('Added !role role to !user', [ + $this->logger()->success(dt('Added !role role to !user', [ '!role' => $role, '!user' => $account->getAccountName(), ])); @@ -197,7 +197,7 @@ public function removeRole(string $role, string $names = '', $options = ['uid' = foreach ($accounts as $id => $account) { $account->removeRole($role); $account->save(); - $this->logger->success(dt('Removed !role role from !user', [ + $this->logger()->success(dt('Removed !role role from !user', [ '!role' => $role, '!user' => $account->getAccountName(), ])); diff --git a/src/Commands/core/WatchdogCommands.php b/src/Commands/core/WatchdogCommands.php index 43f7da4594..8758579586 100644 --- a/src/Commands/core/WatchdogCommands.php +++ b/src/Commands/core/WatchdogCommands.php @@ -345,13 +345,13 @@ protected function where(?string $type = null, $severity = null, ?string $filter * Format a watchdog database row. * * @param $result - * Array. A database result object. + * A database result object. * @param $extended - * Boolean. Return extended message details. + * Return extended message details. * @return - * Array. The result object with some attributes themed. + * The result object with some attributes themed. */ - protected function formatResult($result, bool $extended = false) + protected function formatResult(\stdClass $result, bool $extended = false): \stdClass { // Severity. $severities = RfcLogLevel::getLevels(); diff --git a/src/Commands/pm/PmCommands.php b/src/Commands/pm/PmCommands.php index cb90061b80..2e29f19e01 100644 --- a/src/Commands/pm/PmCommands.php +++ b/src/Commands/pm/PmCommands.php @@ -297,8 +297,8 @@ public function pmList($options = ['format' => 'table', 'type' => 'module,theme' * @param $extension * Object of a single extension info. * - * @return - * String describing extension status. Values: enabled|disabled. + * @return string + * Status. Values: enabled|disabled. */ public function extensionStatus($extension): string { diff --git a/src/Runtime/DependencyInjection.php b/src/Runtime/DependencyInjection.php index 8944b255d9..d83e740b38 100644 --- a/src/Runtime/DependencyInjection.php +++ b/src/Runtime/DependencyInjection.php @@ -11,6 +11,7 @@ use Consolidation\SiteAlias\SiteAliasManagerAwareInterface; use Consolidation\SiteAlias\SiteAliasManagerInterface; use Consolidation\SiteProcess\ProcessManagerAwareInterface; +use Drush\Application; use Drush\Boot\BootstrapManager; use Drush\Cache\CommandCache; use Drush\Command\DrushCommandInfoAlterer; @@ -26,7 +27,6 @@ use League\Container\Container; use League\Container\ContainerInterface; use Robo\Robo; -use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\ConsoleOutput; diff --git a/src/Runtime/RedispatchHook.php b/src/Runtime/RedispatchHook.php index ae1152a4e1..74903cbef2 100644 --- a/src/Runtime/RedispatchHook.php +++ b/src/Runtime/RedispatchHook.php @@ -8,11 +8,11 @@ use Consolidation\AnnotatedCommand\Hooks\InitializeHookInterface; use Consolidation\SiteAlias\SiteAliasManagerAwareInterface; use Consolidation\SiteAlias\SiteAliasManagerAwareTrait; -use Consolidation\SiteProcess\ProcessManager; use Consolidation\SiteProcess\Util\Tty; use Drush\Attributes\HandleRemoteCommands; use Drush\Config\ConfigAwareTrait; use Drush\Drush; +use Drush\SiteAlias\ProcessManager; use Robo\Contract\ConfigAwareInterface; use Symfony\Component\Console\Input\InputInterface; diff --git a/src/Sql/SqlBase.php b/src/Sql/SqlBase.php index 5aa27d7c74..13a49fae1a 100644 --- a/src/Sql/SqlBase.php +++ b/src/Sql/SqlBase.php @@ -312,7 +312,7 @@ public function query(string $query, $input_file = null, $result_file = ''): ?bo * @param $result_file * A path to save query results to. Can be drush_bit_bucket() if desired. * - * @return + * @return bool * TRUE on success, FALSE on failure. */ public function alwaysQuery(string $query, $input_file = null, ?string $result_file = ''): bool @@ -424,13 +424,13 @@ public function drop(array $tables): ?bool /** * Build a SQL string for dropping and creating a database. * - * @param string dbname + * @param $dbname * The database name. - * @param boolean $quoted + * @param $quoted * Quote the database name. Mysql uses backticks to quote which can cause problems * in a Windows shell. Set TRUE if the CREATE is not running on the bash command line. */ - public function createdbSql($dbname, bool $quoted = false): string + public function createdbSql(string $dbname, bool $quoted = false): string { return ''; } @@ -506,7 +506,7 @@ public function listTables(): array /** * Extract the name of all existing tables in the given database. * - * @return + * @return array * An array of table names which exist in the current database, * appropriately quoted for the RDMS. */ @@ -572,7 +572,7 @@ public function getOption($name, $default = null) /** * Convert from an old-style database URL to an array of database settings. * - * @param db_url + * @param $db_url * A Drupal 6 db url string to convert, or an array with a 'default' element. * An array of database values containing only the 'default' element of * the db url. If the parse fails the array is empty. diff --git a/src/Utils/FsUtils.php b/src/Utils/FsUtils.php index a5690aacea..b767fec141 100644 --- a/src/Utils/FsUtils.php +++ b/src/Utils/FsUtils.php @@ -10,23 +10,20 @@ use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Path; -class FsUtils +final class FsUtils { // @var null|string[] List of directories to delete private static $deletionList; /** - * Decide where our backup directory should go + * Return path to the backup directory. * * @param string $subdir * The name of the desired subdirectory(s) under drush-backups. * Usually a database name. - * - * @return - * A path to the backup directory. * @throws \Exception */ - public static function getBackupDir($subdir = null): string + public static function getBackupDir(?string $subdir = null): string { $parent = self::getBackupDirParent(); @@ -45,18 +42,11 @@ public static function getBackupDir($subdir = null): string // Save the date to be used in the backup directory's path name. $date = gmdate('YmdHis', $_SERVER['REQUEST_TIME']); - return Path::join( - $parent, - $date - ); + return Path::join($parent, $date); } /** * Get the base dir where our backup directories will be stored. Also stores CLI history file. - * - * @return - * A path to the backup directory parent - * @throws \Exception */ public static function getBackupDirParent() { diff --git a/src/Utils/StringUtils.php b/src/Utils/StringUtils.php index 5a5a4a7438..911fd26c04 100644 --- a/src/Utils/StringUtils.php +++ b/src/Utils/StringUtils.php @@ -4,7 +4,7 @@ namespace Drush\Utils; -class StringUtils +final class StringUtils { /** * Convert a csv string, or an array of items which