Skip to content

Commit

Permalink
Fix hasSideEffects for AnnotationMethodReflection
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Dec 31, 2022
1 parent 97efd4d commit 9128321
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Reflection/Annotations/AnnotationMethodReflection.php
Expand Up @@ -109,6 +109,10 @@ public function getThrowType(): ?Type

public function hasSideEffects(): TrinaryLogic
{
if ($this->returnType->isVoid()->yes()) {
return TrinaryLogic::createYes();
}

return TrinaryLogic::createMaybe();
}

Expand Down
Expand Up @@ -613,4 +613,10 @@ public function testPhpUnitIntegration(): void
$this->analyse([__DIR__ . '/../../Analyser/data/phpunit-integration.php'], []);
}

public function testBug8586(): void
{
$this->checkAlwaysTrueStrictComparison = true;
$this->analyse([__DIR__ . '/data/bug-8586.php'], []);
}

}
38 changes: 38 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-8586.php
@@ -0,0 +1,38 @@
<?php declare(strict_types = 1);

namespace Bug8586;

class Foo
{
public function getString(): ?string
{
return '';
}
}

/**
* @method void refreshFromAnnotation(object $object)
*/
class EntityManager
{
public function refresh(object $object): void
{
}
}

class HelloWorld
{
public function sayHello(Foo $foo, EntityManager $em): void
{
\assert($foo->getString() === null);
$em->refreshFromAnnotation($foo);
\assert($foo->getString() !== null);
}

public function sayHello2(Foo $foo, EntityManager $em): void
{
\assert($foo->getString() === null);
$em->refresh($foo);
\assert($foo->getString() !== null);
}
}

0 comments on commit 9128321

Please sign in to comment.