Skip to content

Commit 9128321

Browse files
Fix hasSideEffects for AnnotationMethodReflection
1 parent 97efd4d commit 9128321

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/Reflection/Annotations/AnnotationMethodReflection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ public function getThrowType(): ?Type
109109

110110
public function hasSideEffects(): TrinaryLogic
111111
{
112+
if ($this->returnType->isVoid()->yes()) {
113+
return TrinaryLogic::createYes();
114+
}
115+
112116
return TrinaryLogic::createMaybe();
113117
}
114118

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,4 +613,10 @@ public function testPhpUnitIntegration(): void
613613
$this->analyse([__DIR__ . '/../../Analyser/data/phpunit-integration.php'], []);
614614
}
615615

616+
public function testBug8586(): void
617+
{
618+
$this->checkAlwaysTrueStrictComparison = true;
619+
$this->analyse([__DIR__ . '/data/bug-8586.php'], []);
620+
}
621+
616622
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug8586;
4+
5+
class Foo
6+
{
7+
public function getString(): ?string
8+
{
9+
return '';
10+
}
11+
}
12+
13+
/**
14+
* @method void refreshFromAnnotation(object $object)
15+
*/
16+
class EntityManager
17+
{
18+
public function refresh(object $object): void
19+
{
20+
}
21+
}
22+
23+
class HelloWorld
24+
{
25+
public function sayHello(Foo $foo, EntityManager $em): void
26+
{
27+
\assert($foo->getString() === null);
28+
$em->refreshFromAnnotation($foo);
29+
\assert($foo->getString() !== null);
30+
}
31+
32+
public function sayHello2(Foo $foo, EntityManager $em): void
33+
{
34+
\assert($foo->getString() === null);
35+
$em->refresh($foo);
36+
\assert($foo->getString() !== null);
37+
}
38+
}

0 commit comments

Comments
 (0)