From 6f7ae6d19a8df52bfb8c1266becc586cac084d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Wed, 10 Apr 2024 14:45:01 +0200 Subject: [PATCH] Fix errors reported by PHPStan --- phpstan.neon.dist | 28 +--------------------------- src/ExtensionInstaller.php | 21 +++++++++++++-------- src/PluginInstaller.php | 6 +++--- src/SkinInstaller.php | 6 +++--- 4 files changed, 20 insertions(+), 41 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 2df985e..f27b06b 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -12,34 +12,8 @@ parameters: # relax strict rules - '~^Only booleans are allowed in .+, .+ given( on the (left|right) side)?\.~' - '~^Construct empty\(\) is not allowed\. Use more strict comparison\.~' - - '~^Loose comparison via "[=!]=" is not allowed\.~' - - # TODO - - - message: '~^Anonymous function uses \$this assigned to variable \$self. Use \$this directly in the function body\.$~' - path: 'src/ExtensionInstaller.php' - count: 3 + - message: '~^Constant RCMAIL_VERSION not found\.$~' path: 'src/ExtensionInstaller.php' count: 3 - - - message: '~^Method Roundcube\\Composer\\ExtensionInstaller::install\(\) should return React\\Promise\\PromiseInterface|null but return statement is missing\.$~' - path: 'src/ExtensionInstaller.php' - count: 3 - - - message: '~^Undefined variable: \$rootdir$~' - path: 'src/ExtensionInstaller.php' - count: 1 - - - message: '~^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$~' - path: 'src/ExtensionInstaller.php' - count: 1 - - - message: '~^Call to function in_array\(\) requires parameter #3 to be set\.$~' - path: 'src/PluginInstaller.php' - count: 1 - - - message: '~^Call to function array_search\(\) requires parameter #3 to be set\.$~' - path: 'src/PluginInstaller.php' - count: 1 diff --git a/src/ExtensionInstaller.php b/src/ExtensionInstaller.php index 93fcd6b..2e0f695 100644 --- a/src/ExtensionInstaller.php +++ b/src/ExtensionInstaller.php @@ -66,7 +66,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa $package_dir = $this->getVendorDir() . DIRECTORY_SEPARATOR . $package_name; $extra = $package->getExtra(); - if (is_writeable($config_file) && php_sapi_name() == 'cli' && $this->confirmInstall($package_name)) { + if (is_writeable($config_file) && php_sapi_name() === 'cli' && $this->confirmInstall($package_name)) { $this->rcubeAlterConfig($package_name); } @@ -118,6 +118,8 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa // If not, execute the code right away (composer v1, or v2 without async) $postInstall(); + + return null; } /** @@ -194,6 +196,8 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini // If not, execute the code right away (composer v1, or v2 without async) $postUpdate(); + + return null; } /** @@ -239,6 +243,8 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $ // If not, execute the code right away (composer v1, or v2 without async) $postUninstall(); + + return null; } /** @@ -275,10 +281,6 @@ private function rcubeVersionCheck($package) // read rcube version from iniset $rcubeVersion = self::versionNormalize(RCMAIL_VERSION); - if (empty($rcubeVersion)) { - throw new \Exception("Unable to find a Roundcube installation in $rootdir"); - } - $extra = $package->getExtra(); if (!empty($extra['roundcube'])) { @@ -309,7 +311,10 @@ private function rcubeAlterConfig($package_name, $add = true) } if (!empty($config) && is_writeable($config_file)) { - $config_template = @file_get_contents($config_file) ?: ''; + $config_template = @file_get_contents($config_file); + if ($config_template === false) { + $config_template = ''; + } if ($config = $this->getConfig($package_name, $config, $add)) { list($config_name, $config_val) = $config; @@ -342,7 +347,7 @@ private function rcubeAlterConfig($package_name, $add = true) } } - if ($success && php_sapi_name() == 'cli') { + if ($success && php_sapi_name() === 'cli') { $this->io->write("Updated local config at $config_file"); } @@ -417,7 +422,7 @@ private function rcubeRunScript($script, PackageInterface $package) /** * normalize Roundcube version string */ - private static function versionNormalize($version) + private static function versionNormalize(string $version): string { $parser = new VersionParser; diff --git a/src/PluginInstaller.php b/src/PluginInstaller.php index a73ee9e..de026b6 100644 --- a/src/PluginInstaller.php +++ b/src/PluginInstaller.php @@ -38,14 +38,14 @@ protected function getConfig($package_name, $config, $add ) $cur_config = !empty($config['plugins']) ? ((array) $config['plugins']) : []; $new_config = $cur_config; - if ($add && !in_array($package_name, $new_config)) { + if ($add && !in_array($package_name, $new_config, true)) { $new_config[] = $package_name; } - elseif (!$add && ($i = array_search($package_name, $new_config)) !== false) { + elseif (!$add && ($i = array_search($package_name, $new_config, true)) !== false) { unset($new_config[$i]); } - if ($new_config != $cur_config) { + if ($new_config !== $cur_config) { $config_val = count($new_config) > 0 ? "[\n\t'" . join("',\n\t'", $new_config) . "',\n];" : "[];"; $result = ['plugins', $config_val]; } diff --git a/src/SkinInstaller.php b/src/SkinInstaller.php index b47517b..1b99ab8 100644 --- a/src/SkinInstaller.php +++ b/src/SkinInstaller.php @@ -38,14 +38,14 @@ protected function getConfig($package_name, $config, $add) $cur_config = !empty($config['skin']) ? $config['skin'] : null; $new_config = $cur_config; - if ($add && $new_config != $package_name) { + if ($add && $new_config !== $package_name) { $new_config = $package_name; } - elseif (!$add && $new_config == $package_name) { + elseif (!$add && $new_config === $package_name) { $new_config = null; } - if ($new_config != $cur_config) { + if ($new_config !== $cur_config) { $config_val = !empty($new_config) ? "'$new_config';" : null; $result = ['skin', $config_val]; }