Skip to content

Commit

Permalink
Some phpstan Level 1 fixes (#5973)
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Apr 26, 2024
1 parent b5364e5 commit 25e00e5
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -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/
Expand Down
9 changes: 9 additions & 0 deletions src/Commands/DrushCommands.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
7 changes: 4 additions & 3 deletions src/Commands/core/SiteInstallCommands.php
Expand Up @@ -423,22 +423,23 @@ 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 {
$this->logger()->info(dt('Sites directory @subdir already exists - proceeding.', ['@subdir' => $confPath]));
}

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]));
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/core/UserCommands.php
Expand Up @@ -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()]));
}
}

Expand All @@ -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()]));
}
}

Expand All @@ -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(),
]));
Expand All @@ -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(),
]));
Expand Down
8 changes: 4 additions & 4 deletions src/Commands/core/WatchdogCommands.php
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/pm/PmCommands.php
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/DependencyInjection.php
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Runtime/RedispatchHook.php
Expand Up @@ -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;

Expand Down
12 changes: 6 additions & 6 deletions src/Sql/SqlBase.php
Expand Up @@ -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
Expand Down Expand Up @@ -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 '';
}
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 4 additions & 14 deletions src/Utils/FsUtils.php
Expand Up @@ -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();

Expand All @@ -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()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Utils/StringUtils.php
Expand Up @@ -4,7 +4,7 @@

namespace Drush\Utils;

class StringUtils
final class StringUtils
{
/**
* Convert a csv string, or an array of items which
Expand Down

0 comments on commit 25e00e5

Please sign in to comment.