From b698def51afb75860cfcdf24e258f62050fd1c5d Mon Sep 17 00:00:00 2001 From: Mikko Pesari Date: Thu, 19 Dec 2024 16:22:21 +0200 Subject: [PATCH] misc: fix PHP 8.4 deprecations --- qa/Psalm/ValinorPsalmPlugin.php | 2 +- tests/Fake/Definition/FakeFunctionDefinition.php | 2 +- tests/Fake/Definition/FakeParameterDefinition.php | 2 +- tests/Fake/Mapper/Tree/Builder/FakeNodeBuilder.php | 2 +- tests/Fake/Mapper/Tree/Builder/FakeTreeNode.php | 4 ++-- tests/Fake/Type/FakeType.php | 2 +- tests/StaticAnalysis/inferring-types-with-plugin.php | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/qa/Psalm/ValinorPsalmPlugin.php b/qa/Psalm/ValinorPsalmPlugin.php index 3eb2b1ce..48cf225c 100644 --- a/qa/Psalm/ValinorPsalmPlugin.php +++ b/qa/Psalm/ValinorPsalmPlugin.php @@ -10,7 +10,7 @@ class ValinorPsalmPlugin implements PluginEntryPointInterface { - public function __invoke(RegistrationInterface $api, SimpleXMLElement $config = null): void + public function __invoke(RegistrationInterface $api, ?SimpleXMLElement $config = null): void { require_once __DIR__ . '/Plugin/TreeMapperPsalmPlugin.php'; require_once __DIR__ . '/Plugin/ArgumentsMapperPsalmPlugin.php'; diff --git a/tests/Fake/Definition/FakeFunctionDefinition.php b/tests/Fake/Definition/FakeFunctionDefinition.php index e7771e03..b8c8716b 100644 --- a/tests/Fake/Definition/FakeFunctionDefinition.php +++ b/tests/Fake/Definition/FakeFunctionDefinition.php @@ -16,7 +16,7 @@ final class FakeFunctionDefinition /** * @param non-empty-string|null $fileName */ - public static function new(string $fileName = null): FunctionDefinition + public static function new(?string $fileName = null): FunctionDefinition { return new FunctionDefinition( 'foo', diff --git a/tests/Fake/Definition/FakeParameterDefinition.php b/tests/Fake/Definition/FakeParameterDefinition.php index 375fd59d..671cf103 100644 --- a/tests/Fake/Definition/FakeParameterDefinition.php +++ b/tests/Fake/Definition/FakeParameterDefinition.php @@ -17,7 +17,7 @@ private function __construct() {} /** * @param non-empty-string $name */ - public static function new(string $name = 'someParameter', Type $type = null): ParameterDefinition + public static function new(string $name = 'someParameter', ?Type $type = null): ParameterDefinition { return new ParameterDefinition( $name, diff --git a/tests/Fake/Mapper/Tree/Builder/FakeNodeBuilder.php b/tests/Fake/Mapper/Tree/Builder/FakeNodeBuilder.php index e7ee973c..091bdd8d 100644 --- a/tests/Fake/Mapper/Tree/Builder/FakeNodeBuilder.php +++ b/tests/Fake/Mapper/Tree/Builder/FakeNodeBuilder.php @@ -17,7 +17,7 @@ final class FakeNodeBuilder implements NodeBuilder /** * @param null|callable(Shell): TreeNode $callback */ - public function __construct(callable $callback = null) + public function __construct(?callable $callback = null) { if ($callback) { $this->callback = $callback; diff --git a/tests/Fake/Mapper/Tree/Builder/FakeTreeNode.php b/tests/Fake/Mapper/Tree/Builder/FakeTreeNode.php index 0ffba879..0ece7dab 100644 --- a/tests/Fake/Mapper/Tree/Builder/FakeTreeNode.php +++ b/tests/Fake/Mapper/Tree/Builder/FakeTreeNode.php @@ -30,7 +30,7 @@ public static function leaf(Type $type, mixed $value): TreeNode /** * @param array $children */ - public static function branch(array $children, Type $type = null, mixed $value = null): TreeNode + public static function branch(array $children, ?Type $type = null, mixed $value = null): TreeNode { $shell = FakeShell::new($type ?? FakeType::permissive(), $value); $nodes = []; @@ -58,7 +58,7 @@ public static function branch(array $children, Type $type = null, mixed $value = /** * @param Throwable&Message $error */ - public static function error(Throwable $error = null): TreeNode + public static function error(?Throwable $error = null): TreeNode { $shell = FakeShell::new(FakeType::permissive(), []); diff --git a/tests/Fake/Type/FakeType.php b/tests/Fake/Type/FakeType.php index e3548887..8b854102 100644 --- a/tests/Fake/Type/FakeType.php +++ b/tests/Fake/Type/FakeType.php @@ -29,7 +29,7 @@ final class FakeType implements Type private bool $permissive = false; - public function __construct(string $name = null) + public function __construct(?string $name = null) { $this->name = $name ?? 'FakeType' . self::$counter++; } diff --git a/tests/StaticAnalysis/inferring-types-with-plugin.php b/tests/StaticAnalysis/inferring-types-with-plugin.php index b403c031..5af11d59 100644 --- a/tests/StaticAnalysis/inferring-types-with-plugin.php +++ b/tests/StaticAnalysis/inferring-types-with-plugin.php @@ -44,7 +44,7 @@ function mapping_union_of_types_will_infer_correct_type(TreeMapper $mapper): voi function mapping_function_arguments_will_infer_object_of_same_type(ArgumentsMapper $mapper): void { - $result = $mapper->mapArguments(fn (string $foo, int $bar = null): string => "$foo / $bar", []); + $result = $mapper->mapArguments(fn (string $foo, ?int $bar = null): string => "$foo / $bar", []); /** @psalm-check-type $result = array{foo: string, bar?: int|null} */ assertType('array{foo: string, bar?: int|null}', $result); @@ -68,12 +68,12 @@ function mapping_method_arguments_will_infer_object_of_same_type(ArgumentsMapper final class SomeClass { - public static function someStaticMethod(string $foo, int $bar = null): string + public static function someStaticMethod(string $foo, ?int $bar = null): string { return "$foo / $bar"; } - public function someMethod(string $foo, int $bar = null): string + public function someMethod(string $foo, ?int $bar = null): string { return "$foo / $bar"; }