From dfac9f5813df7d4c7c812c381364c8898333f559 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 11 Sep 2024 17:14:53 +0200 Subject: PHPStan booleansInConditions (#6793) * PHPStan booleansInConditions * Uniformisation --- cli/CliOptionsParser.php | 11 ++++++----- cli/create-user.php | 2 +- cli/update-user.php | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'cli') diff --git a/cli/CliOptionsParser.php b/cli/CliOptionsParser.php index f0c6bf9a2..5a2d353db 100644 --- a/cli/CliOptionsParser.php +++ b/cli/CliOptionsParser.php @@ -11,6 +11,7 @@ abstract class CliOptionsParser { public string $usage = ''; public function __construct() { + /** @var array $argv */ global $argv; $this->usage = $this->getUsageMessage($argv[0]); @@ -82,7 +83,7 @@ abstract class CliOptionsParser { foreach ($this->inputs as $name => $input) { $values = $input['values'] ?? $input['defaultInput'] ?? null; $types = $this->options[$name]->getTypes(); - if ($values) { + if (!empty($values)) { $validValues = []; $typedValues = []; @@ -205,8 +206,8 @@ abstract class CliOptionsParser { foreach ($this->options as $option) { $long[] = $option->getLongAlias() . $getoptNotation[$option->getValueTaken()]; - $long[] = $option->getDeprecatedAlias() ? $option->getDeprecatedAlias() . $getoptNotation[$option->getValueTaken()] : ''; - $short .= $option->getShortAlias() ? $option->getShortAlias() . $getoptNotation[$option->getValueTaken()] : ''; + $long[] = $option->getDeprecatedAlias() != null ? $option->getDeprecatedAlias() . $getoptNotation[$option->getValueTaken()] : ''; + $short .= $option->getShortAlias() != null ? $option->getShortAlias() . $getoptNotation[$option->getValueTaken()] : ''; } return [ @@ -220,7 +221,7 @@ abstract class CliOptionsParser { $optional = []; foreach ($this->options as $name => $option) { - $shortAlias = $option->getShortAlias() ? '-' . $option->getShortAlias() . ' ' : ''; + $shortAlias = $option->getShortAlias() != null ? '-' . $option->getShortAlias() . ' ' : ''; $longAlias = '--' . $option->getLongAlias() . ($option->getValueTaken() === 'required' ? '=<' . strtolower($name) . '>' : ''); if ($this->inputs[$name]['required']) { $required[] = $shortAlias . $longAlias; @@ -235,7 +236,7 @@ abstract class CliOptionsParser { private function makeInputRegex(): string { $shortWithValues = ''; foreach ($this->options as $option) { - if (($option->getValueTaken() === 'required' || $option->getValueTaken() === 'optional') && $option->getShortAlias()) { + if (($option->getValueTaken() === 'required' || $option->getValueTaken() === 'optional') && $option->getShortAlias() != null) { $shortWithValues .= $option->getShortAlias(); } } diff --git a/cli/create-user.php b/cli/create-user.php index 1be604a42..ae560b49e 100755 --- a/cli/create-user.php +++ b/cli/create-user.php @@ -58,7 +58,7 @@ if (!empty($cliOptions->errors)) { $username = $cliOptions->user; -if (preg_grep("/^$username$/i", listUsers())) { +if (!empty(preg_grep("/^$username$/i", listUsers()))) { fail('FreshRSS warning: username already exists “' . $username . '”', EXIT_CODE_ALREADY_EXISTS); } diff --git a/cli/update-user.php b/cli/update-user.php index ff0177997..553025d2b 100755 --- a/cli/update-user.php +++ b/cli/update-user.php @@ -80,7 +80,7 @@ if (!$ok) { if (isset($cliOptions->apiPassword)) { $error = FreshRSS_api_Controller::updatePassword($cliOptions->apiPassword); - if ($error) { + if ($error !== false) { fail($error); } } -- cgit v1.2.3