Skip to content

Commit 6f7ae6d

Browse files
committed
Fix errors reported by PHPStan
1 parent 13699c3 commit 6f7ae6d

4 files changed

Lines changed: 20 additions & 41 deletions

File tree

phpstan.neon.dist

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,8 @@ parameters:
1212
# relax strict rules
1313
- '~^Only booleans are allowed in .+, .+ given( on the (left|right) side)?\.~'
1414
- '~^Construct empty\(\) is not allowed\. Use more strict comparison\.~'
15-
- '~^Loose comparison via "[=!]=" is not allowed\.~'
16-
17-
# TODO
18-
-
19-
message: '~^Anonymous function uses \$this assigned to variable \$self. Use \$this directly in the function body\.$~'
20-
path: 'src/ExtensionInstaller.php'
21-
count: 3
15+
2216
-
2317
message: '~^Constant RCMAIL_VERSION not found\.$~'
2418
path: 'src/ExtensionInstaller.php'
2519
count: 3
26-
-
27-
message: '~^Method Roundcube\\Composer\\ExtensionInstaller::install\(\) should return React\\Promise\\PromiseInterface<void\|null>|null but return statement is missing\.$~'
28-
path: 'src/ExtensionInstaller.php'
29-
count: 3
30-
-
31-
message: '~^Undefined variable: \$rootdir$~'
32-
path: 'src/ExtensionInstaller.php'
33-
count: 1
34-
-
35-
message: '~^Short ternary operator is not allowed\. Use null coalesce operator if applicable or consider using long ternary\.$~'
36-
path: 'src/ExtensionInstaller.php'
37-
count: 1
38-
-
39-
message: '~^Call to function in_array\(\) requires parameter #3 to be set\.$~'
40-
path: 'src/PluginInstaller.php'
41-
count: 1
42-
-
43-
message: '~^Call to function array_search\(\) requires parameter #3 to be set\.$~'
44-
path: 'src/PluginInstaller.php'
45-
count: 1

src/ExtensionInstaller.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
6666
$package_dir = $this->getVendorDir() . DIRECTORY_SEPARATOR . $package_name;
6767
$extra = $package->getExtra();
6868

69-
if (is_writeable($config_file) && php_sapi_name() == 'cli' && $this->confirmInstall($package_name)) {
69+
if (is_writeable($config_file) && php_sapi_name() === 'cli' && $this->confirmInstall($package_name)) {
7070
$this->rcubeAlterConfig($package_name);
7171
}
7272

@@ -118,6 +118,8 @@ public function install(InstalledRepositoryInterface $repo, PackageInterface $pa
118118

119119
// If not, execute the code right away (composer v1, or v2 without async)
120120
$postInstall();
121+
122+
return null;
121123
}
122124

123125
/**
@@ -194,6 +196,8 @@ public function update(InstalledRepositoryInterface $repo, PackageInterface $ini
194196

195197
// If not, execute the code right away (composer v1, or v2 without async)
196198
$postUpdate();
199+
200+
return null;
197201
}
198202

199203
/**
@@ -239,6 +243,8 @@ public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $
239243

240244
// If not, execute the code right away (composer v1, or v2 without async)
241245
$postUninstall();
246+
247+
return null;
242248
}
243249

244250
/**
@@ -275,10 +281,6 @@ private function rcubeVersionCheck($package)
275281
// read rcube version from iniset
276282
$rcubeVersion = self::versionNormalize(RCMAIL_VERSION);
277283

278-
if (empty($rcubeVersion)) {
279-
throw new \Exception("Unable to find a Roundcube installation in $rootdir");
280-
}
281-
282284
$extra = $package->getExtra();
283285

284286
if (!empty($extra['roundcube'])) {
@@ -309,7 +311,10 @@ private function rcubeAlterConfig($package_name, $add = true)
309311
}
310312

311313
if (!empty($config) && is_writeable($config_file)) {
312-
$config_template = @file_get_contents($config_file) ?: '';
314+
$config_template = @file_get_contents($config_file);
315+
if ($config_template === false) {
316+
$config_template = '';
317+
}
313318

314319
if ($config = $this->getConfig($package_name, $config, $add)) {
315320
list($config_name, $config_val) = $config;
@@ -342,7 +347,7 @@ private function rcubeAlterConfig($package_name, $add = true)
342347
}
343348
}
344349

345-
if ($success && php_sapi_name() == 'cli') {
350+
if ($success && php_sapi_name() === 'cli') {
346351
$this->io->write("<info>Updated local config at $config_file</info>");
347352
}
348353

@@ -417,7 +422,7 @@ private function rcubeRunScript($script, PackageInterface $package)
417422
/**
418423
* normalize Roundcube version string
419424
*/
420-
private static function versionNormalize($version)
425+
private static function versionNormalize(string $version): string
421426
{
422427
$parser = new VersionParser;
423428

src/PluginInstaller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ protected function getConfig($package_name, $config, $add )
3838
$cur_config = !empty($config['plugins']) ? ((array) $config['plugins']) : [];
3939
$new_config = $cur_config;
4040

41-
if ($add && !in_array($package_name, $new_config)) {
41+
if ($add && !in_array($package_name, $new_config, true)) {
4242
$new_config[] = $package_name;
4343
}
44-
elseif (!$add && ($i = array_search($package_name, $new_config)) !== false) {
44+
elseif (!$add && ($i = array_search($package_name, $new_config, true)) !== false) {
4545
unset($new_config[$i]);
4646
}
4747

48-
if ($new_config != $cur_config) {
48+
if ($new_config !== $cur_config) {
4949
$config_val = count($new_config) > 0 ? "[\n\t'" . join("',\n\t'", $new_config) . "',\n];" : "[];";
5050
$result = ['plugins', $config_val];
5151
}

src/SkinInstaller.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ protected function getConfig($package_name, $config, $add)
3838
$cur_config = !empty($config['skin']) ? $config['skin'] : null;
3939
$new_config = $cur_config;
4040

41-
if ($add && $new_config != $package_name) {
41+
if ($add && $new_config !== $package_name) {
4242
$new_config = $package_name;
4343
}
44-
elseif (!$add && $new_config == $package_name) {
44+
elseif (!$add && $new_config === $package_name) {
4545
$new_config = null;
4646
}
4747

48-
if ($new_config != $cur_config) {
48+
if ($new_config !== $cur_config) {
4949
$config_val = !empty($new_config) ? "'$new_config';" : null;
5050
$result = ['skin', $config_val];
5151
}

0 commit comments

Comments
 (0)