diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 2f22e74f78..b55a59cf1c 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -521,7 +521,7 @@ private function processStmtNode( $param->var->name, $param->flags, $param->type, - $param->default, + null, $phpDoc, true, $param diff --git a/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php b/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php index 6c4dfc45a6..389e96e526 100644 --- a/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php +++ b/tests/PHPStan/Rules/Methods/IncompatibleDefaultParameterTypeRuleTest.php @@ -59,4 +59,22 @@ public function testNewInInitializers(): void ]); } + public function testDefaultValueForPromotedProperty(): void + { + if (!self::$useStaticReflectionProvider) { + $this->markTestSkipped('Test requires static reflection.'); + } + + $this->analyse([__DIR__ . '/data/default-value-for-promoted-property.php'], [ + [ + 'Default value of the parameter #1 $foo (string) of method DefaultValueForPromotedProperty\Foo::__construct() is incompatible with type int.', + 9, + ], + [ + 'Default value of the parameter #2 $foo (string) of method DefaultValueForPromotedProperty\Foo::__construct() is incompatible with type int.', + 10, + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Properties/data/default-value-for-promoted-property.php b/tests/PHPStan/Rules/Methods/data/default-value-for-promoted-property.php similarity index 100% rename from tests/PHPStan/Rules/Properties/data/default-value-for-promoted-property.php rename to tests/PHPStan/Rules/Methods/data/default-value-for-promoted-property.php diff --git a/tests/PHPStan/Rules/Properties/DefaultValueTypesAssignedToPropertiesRuleTest.php b/tests/PHPStan/Rules/Properties/DefaultValueTypesAssignedToPropertiesRuleTest.php index 42064cd3e8..9588d3f87d 100644 --- a/tests/PHPStan/Rules/Properties/DefaultValueTypesAssignedToPropertiesRuleTest.php +++ b/tests/PHPStan/Rules/Properties/DefaultValueTypesAssignedToPropertiesRuleTest.php @@ -47,22 +47,4 @@ public function testDefaultValueForNativePropertyType(): void ]); } - public function testDefaultValueForPromotedProperty(): void - { - if (!self::$useStaticReflectionProvider) { - $this->markTestSkipped('Test requires static reflection.'); - } - - $this->analyse([__DIR__ . '/data/default-value-for-promoted-property.php'], [ - [ - 'Property DefaultValueForPromotedProperty\Foo::$foo (int) does not accept default value of type string.', - 9, - ], - [ - 'Property DefaultValueForPromotedProperty\Foo::$foo (int) does not accept default value of type string.', - 10, - ], - ]); - } - } diff --git a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php index 7bcd73b7c9..c88a70e9ee 100644 --- a/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php +++ b/tests/PHPStan/Rules/Properties/ReadOnlyPropertyRuleTest.php @@ -46,6 +46,10 @@ public function dataRule(): array 'Readonly property cannot have a default value.', 10, ], + [ + 'Readonly properties are supported only on PHP 8.1 and later.', + 16, + ], ], ], [ diff --git a/tests/PHPStan/Rules/Properties/data/read-only-property.php b/tests/PHPStan/Rules/Properties/data/read-only-property.php index a360e2419b..979cf94e91 100644 --- a/tests/PHPStan/Rules/Properties/data/read-only-property.php +++ b/tests/PHPStan/Rules/Properties/data/read-only-property.php @@ -10,3 +10,10 @@ class Foo private readonly int $baz = 0; } + +final class ErrorResponse +{ + public function __construct(public readonly string $message = '') + { + } +}