Skip to content

Commit 39c862b

Browse files
committed
Merge branch 2.2.x into 2.3.x
2 parents 9c947a1 + 9aa319a commit 39c862b

4 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎phpstan-baseline.neon‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ parameters:
16291629
-
16301630
rawMessage: 'Doing instanceof PHPStan\Type\NullType is error-prone and deprecated. Use Type::isNull() instead.'
16311631
identifier: phpstanApi.instanceofType
1632-
count: 2
1632+
count: 1
16331633
path: src/Type/TypeCombinator.php
16341634

16351635
-

‎src/Type/TypeCombinator.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public static function containsNull(Type $type): bool
175175
{
176176
if ($type instanceof UnionType) {
177177
foreach ($type->getTypes() as $innerType) {
178-
if ($innerType instanceof NullType) {
178+
if ($innerType->isNull()->yes()) {
179179
return true;
180180
}
181181
}

‎tests/PHPStan/Rules/Methods/CallMethodsRuleTest.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,15 @@ public function testNullSafe(): void
19241924
]);
19251925
}
19261926

1927+
public function testNullSafeOnTemplateTypeNarrowedAgainstNull(): void
1928+
{
1929+
$this->checkThisOnly = false;
1930+
$this->checkNullables = true;
1931+
$this->checkUnionTypes = true;
1932+
1933+
$this->analyse([__DIR__ . '/data/nullsafe-method-call-template-type.php'], []);
1934+
}
1935+
19271936
#[RequiresPhp('< 8.0.0')]
19281937
public function testDisallowNamedArguments(): void
19291938
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php // lint >= 8.0
2+
3+
namespace NullsafeMethodCallTemplateType;
4+
5+
class Foo
6+
{
7+
8+
public function getValue(): ?string
9+
{
10+
return null;
11+
}
12+
13+
}
14+
15+
/**
16+
* @template T
17+
* @param T $foo
18+
*/
19+
function foo($foo)
20+
{
21+
if ($foo !== null && !$foo instanceof Foo) {
22+
throw new \Exception();
23+
}
24+
25+
return $foo?->getValue();
26+
}

0 commit comments

Comments
 (0)