Skip to content

Commit

Permalink
Fix errors reported by PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 10, 2024
1 parent 13699c3 commit 6f7ae6d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 41 deletions.
28 changes: 1 addition & 27 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -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<void\|null>|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
21 changes: 13 additions & 8 deletions src/ExtensionInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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("<info>Updated local config at $config_file</info>");
}

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions src/PluginInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
6 changes: 3 additions & 3 deletions src/SkinInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit 6f7ae6d

Please sign in to comment.