Skip to content

Commit 6115511

Browse files
committed
TooWidePropertyTypeRule - property without native type and with default value is not implicitly nullable
1 parent 2ecc069 commit 6115511

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function checkProperty(
7474
$assignedTypes[] = $scope->getType($node->getDefault());
7575
}
7676

77-
if ($node->getNativeType() === null) {
77+
if ($node->getNativeType() === null && $node->getDefault() === null) {
7878
$assignedTypes[] = new NullType();
7979
}
8080

tests/PHPStan/Rules/TooWideTypehints/TooWidePropertyTypeRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public function testRule(): void
3232
'Property TooWidePropertyType\Foo::$foo (int|string) is never assigned string so it can be removed from the property type.',
3333
9,
3434
],
35-
/*[
35+
[
3636
'Property TooWidePropertyType\Foo::$barr (int|null) is never assigned null so it can be removed from the property type.',
3737
15,
3838
],
39-
[
39+
/*[
4040
'Property TooWidePropertyType\Foo::$barrr (int|null) is never assigned null so it can be removed from the property type.',
4141
18,
4242
],*/

0 commit comments

Comments
 (0)