Skip to content

Commit 4aa016e

Browse files
committed
Fix issues reported by PHPStan running on PHP 8.5
1 parent 6fee1ce commit 4aa016e

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

src/Toolkit/Cli/CliCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ final protected function applyOptionValues(
783783
$name = $option->Name;
784784
}
785785
$_value = $option->applyValue($value, $normalise, $expand);
786-
$_values[$name] = $_value;
786+
$_values[(string) $name] = $_value;
787787
$this->OptionValues[$option->Key] = $_value;
788788
if ($asArguments) {
789789
// If the option has an optional value and no value was given,
@@ -825,7 +825,7 @@ final protected function normaliseOptionValues(
825825
if (!$schema) {
826826
$name = $option->Name;
827827
}
828-
$_values[$name] = $option->normaliseValue($value, $expand);
828+
$_values[(string) $name] = $option->normaliseValue($value, $expand);
829829
}
830830

831831
return $_values ?? [];
@@ -901,7 +901,7 @@ final protected function getOptionValues(
901901
} else {
902902
$value = $this->OptionValues[$option->Key] ?? null;
903903
}
904-
$values[$name] = $value;
904+
$values[(string) $name] = $value;
905905
}
906906

907907
/** @var array<array<string|int|bool|float>|string|int|bool|float|null> */
@@ -926,7 +926,7 @@ final protected function getDefaultOptionValues(bool $schema = false): array
926926
continue;
927927
}
928928
$name = $schema ? $key : $option->Name;
929-
$values[$name] = $option->OriginalDefaultValue;
929+
$values[(string) $name] = $option->OriginalDefaultValue;
930930
}
931931

932932
/** @var array<array<string|int|bool|float>|string|int|bool|float|null> */
@@ -1122,7 +1122,7 @@ function (string $key, $value) use (&$argValues, &$saved, &$option) {
11221122
continue;
11231123
}
11241124

1125-
$option = $this->OptionsByName[$name] ?? null;
1125+
$option = $this->OptionsByName[(string) $name] ?? null;
11261126
if (!$option || $option->IsPositional) {
11271127
$this->optionError(sprintf("unknown option '%s'", $name));
11281128
continue;

src/Toolkit/Core/Concern/ImmutableTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ private function propertyIsInitialized(string $property): bool
7171
}
7272

7373
$property = new ReflectionProperty($this, $property);
74-
$property->setAccessible(true);
74+
if (PHP_VERSION_ID < 80100) {
75+
$property->setAccessible(true);
76+
}
7577
return $property->isInitialized($this);
7678
}
7779
}

src/Toolkit/Core/Reflection/ClassReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ public function getPropertyRelationships(): array
612612
? $normaliser($property, false)
613613
: $property;
614614
// @phpstan-ignore argument.type (PHPStan regression)
615-
$relationships[$name] = new PropertyRelationship($property, $type, $target);
615+
$relationships[(string) $name] = new PropertyRelationship($property, $type, $target);
616616
}
617617
$relationships = array_intersect_key($relationships, $declared);
618618
if (count($relationships) !== 2) {

src/Toolkit/Sli/Command/Generate/AbstractGenerateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ protected function getPHPDocTypeAlias(
545545
return strpos($t, '\\') !== false
546546
? $this->getTypeAlias($t)
547547
: $this->getTypeAlias(
548-
$this->InputFileUseMaps[$filename][Str::lower($t)]
548+
$this->InputFileUseMaps[(string) $filename][Str::lower($t)]
549549
?? $this->applyNamespace($t, $namespace),
550550
$filename,
551551
);

src/Toolkit/Utility/Internal/Copier.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ private function doCopy($var)
163163
continue;
164164
}
165165

166-
$property->setAccessible(true);
166+
if (PHP_VERSION_ID < 80100) {
167+
$property->setAccessible(true);
168+
}
167169

168170
if (!$property->isInitialized($clone)) {
169171
continue;

src/Toolkit/Utility/Internal/Exporter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ function ($matches) use (&$utf8Escapes) {
180180
? (($dec = octdec($matches['octal'])) === 27
181181
? '\e'
182182
: sprintf('\x%02x', $dec))
183-
// @phpstan-ignore offsetAccess.notFound
184-
: sprintf('\x%02x', ['a' => 7, 'b' => 8][$matches['cslash']]))),
183+
: sprintf('\x%02x', ['a' => 7, 'b' => 8][(string) $matches['cslash']]))),
185184
$double,
186185
-1,
187186
$count,

src/Toolkit/Utility/Test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function isBoolean($value): bool
2929
* Check if a value is an integer or integer string
3030
*
3131
* @param mixed $value
32-
* @phpstan-assert-if-true int|non-empty-string $value
32+
* @phpstan-assert-if-true int|numeric-string $value
3333
*/
3434
public static function isInteger($value): bool
3535
{
@@ -45,7 +45,7 @@ public static function isInteger($value): bool
4545
* Returns `false` if `$value` is an integer string.
4646
*
4747
* @param mixed $value
48-
* @phpstan-assert-if-true float|non-empty-string $value
48+
* @phpstan-assert-if-true float|numeric-string $value
4949
*/
5050
public static function isFloat($value): bool
5151
{
@@ -61,7 +61,7 @@ public static function isFloat($value): bool
6161
* an array key
6262
*
6363
* @param mixed $value
64-
* @phpstan-assert-if-true int|float|bool|non-empty-string $value
64+
* @phpstan-assert-if-true int|float|bool|numeric-string $value
6565
*/
6666
public static function isNumericKey($value): bool
6767
{

tests/fixtures/Toolkit/Cli/Command/TestOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private function getCallbacks(): array
260260
/** @var string */
261261
$name = $option->Name;
262262
if ($this->optionHasArgument($name)) {
263-
$hasArg[$option->Name] = true;
263+
$hasArg[$name] = true;
264264
}
265265
}
266266
return $this->removeHidden($hasArg ?? []);

tests/phpstan-conditional.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
];
3434

3535
$ignoreErrors = [
36+
...(\PHP_VERSION_ID < 80500 ? [] : [
37+
[
38+
'message' => '#^Call to deprecated method setAccessible\(\) of class ReflectionProperty\.$#',
39+
'identifier' => 'method.deprecated',
40+
],
41+
]),
3642
...(\PHP_VERSION_ID < 80400 ? [] : [
3743
[
3844
'identifier' => 'unset.possiblyHookedProperty',

0 commit comments

Comments
 (0)