Skip to content

Commit db324e7

Browse files
committed
PHPStan v2
1 parent 2f1ddc9 commit db324e7

File tree

12 files changed

+26
-27
lines changed

12 files changed

+26
-27
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
},
3030
"require-dev": {
3131
"clue/phar-composer": "^1.4",
32-
"phpstan/phpstan": "^1.12",
32+
"phpstan/phpstan": "^2.0",
3333
"phpunit/phpunit": "^11.4"
3434
},
3535
"suggest": {

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
parameters:
22
level: 6
3+
treatPhpDocTypesAsCertain: false
34
paths:
45
- src

src/Config.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,9 @@ public static function get(string $key, $default = null) {
5252
* @return array<string, mixed>
5353
*/
5454
private static function getEnvConfig(array $config): array {
55-
$vars = preg_grep('/^PCA_/', array_keys(getenv()));
56-
57-
if ($vars !== false && count($vars)) {
58-
foreach ($vars as $var) {
59-
self::envVarToArray($config, $var, (string) getenv($var));
55+
foreach (getenv() as $var => $value) {
56+
if (str_starts_with($var, 'PCA_')) {
57+
$config = self::envVarToArray($config, $var, $value);
6058
}
6159
}
6260

@@ -66,14 +64,15 @@ private static function getEnvConfig(array $config): array {
6664
/**
6765
* Convert ENV variable to an array.
6866
*
69-
* It allows app to use ENV variables and config.php together.
67+
* It allows the app to use ENV variables and config.php together.
7068
*
7169
* @param array<string, mixed> $array
70+
*
71+
* @return array<string, mixed>
7272
*/
73-
private static function envVarToArray(array &$array, string $var, string $value): void {
74-
$var = str_replace('PCA_', '', $var);
75-
$keys = explode('_', $var);
76-
$keys = array_map(strtolower(...), $keys);
73+
private static function envVarToArray(array $array, string $var, string $value): array {
74+
$var = substr($var, 4);
75+
$keys = array_map(strtolower(...), explode('_', $var));
7776

7877
foreach ($keys as $i => $key) {
7978
if (count($keys) === 1) {
@@ -85,8 +84,6 @@ private static function envVarToArray(array &$array, string $var, string $value)
8584
if (!isset($array[$key]) || !is_array($array[$key])) {
8685
$array[$key] = [];
8786
}
88-
89-
$array = &$array[$key];
9087
}
9188

9289
if (json_validate($value)) {
@@ -98,6 +95,8 @@ private static function envVarToArray(array &$array, string $var, string $value)
9895
}
9996

10097
$array[array_shift($keys)] = $value;
98+
99+
return $array;
101100
}
102101

103102
/**

src/Dashboards/APCu/APCuDashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static function check(): bool {
2323
}
2424

2525
/**
26-
* @return array<string, string|array<int, string>>
26+
* @return array<string, array<int, string>|string>
2727
*/
2828
public function dashboardInfo(): array {
2929
return [

src/Dashboards/APCu/APCuTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ private function viewKey(): string {
120120
public function saveKey(): void {
121121
$key = Http::post('key', '');
122122
$expire = Http::post('expire', 0);
123-
$old_key = Http::post('old_key', '');
123+
$old_key = (string) Http::post('old_key', '');
124124
$value = Value::converter(Http::post('value', ''), Http::post('encoder', ''), 'save');
125125

126-
if ($old_key !== '' && $old_key !== $key) {
126+
if ($old_key !== $key) {
127127
apcu_delete($old_key);
128128
}
129129

src/Dashboards/DashboardInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static function check(): bool;
1717
/**
1818
* Array that contains key, name, and optionally an icon or colors.
1919
*
20-
* @return array<string, string|array<int, string>>
20+
* @return array<string, array<int, string>|string>
2121
*/
2222
public function dashboardInfo(): array;
2323

src/Dashboards/Memcached/MemcachedTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ private function viewKey(): string {
153153
public function saveKey(): void {
154154
$key = Http::post('key', '');
155155
$expire = Http::post('expire', 0);
156-
$old_key = Http::post('old_key', '');
156+
$old_key = (string) Http::post('old_key', '');
157157
$value = Value::converter(Http::post('value', ''), Http::post('encoder', ''), 'save');
158158

159-
if ($old_key !== '' && $old_key !== $key) {
159+
if ($old_key !== $key) {
160160
$this->memcached->delete($old_key);
161161
}
162162

src/Dashboards/OPCache/OPCacheDashboard.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public function __construct(private readonly Template $template) {
1919
}
2020

2121
public static function check(): bool {
22-
return extension_loaded('Zend OPcache') && ini_get('opcache.restrict_api') !== null;
22+
return extension_loaded('Zend OPcache') && ini_get('opcache.restrict_api') !== false;
2323
}
2424

2525
/**
26-
* @return array<string, string|array<int, string>>
26+
* @return array<string, array<int, string>|string>
2727
*/
2828
public function dashboardInfo(): array {
2929
return [

src/Dashboards/Realpath/RealpathDashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function check(): bool {
3030
}
3131

3232
/**
33-
* @return array<string, string>
33+
* @return array<string, array<int, string>|string>
3434
*/
3535
public function dashboardInfo(): array {
3636
return [

src/Dashboards/Redis/RedisDashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function check(): bool {
4242
}
4343

4444
/**
45-
* @return array<string, string|array<int, string>>
45+
* @return array<string, array<int, string>|string>
4646
*/
4747
public function dashboardInfo(): array {
4848
return [

0 commit comments

Comments
 (0)