Skip to content

Commit c7e1125

Browse files
Fix
1 parent 204e0e3 commit c7e1125

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/Type/Symfony/BrowserKitAssertionTraitReturnTypeExtension.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
use PhpParser\Node\Identifier;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Type\ExpressionTypeResolverExtension;
10+
use PHPStan\Type\NullType;
1011
use PHPStan\Type\ObjectType;
1112
use PHPStan\Type\Type;
13+
use PHPStan\Type\TypeCombinator;
14+
use PHPStan\Type\UnionType;
1215
use function count;
1316

1417
final class BrowserKitAssertionTraitReturnTypeExtension implements ExpressionTypeResolverExtension
@@ -22,7 +25,13 @@ public function getType(Expr $expr, Scope $scope): ?Type
2225
if ($this->isSupported($expr, $scope)) {
2326
$args = $expr->getArgs();
2427
if (count($args) > 0) {
25-
return $scope->getType($args[0]->value);
28+
return TypeCombinator::intersect(
29+
$scope->getType($args[0]->value),
30+
new UnionType([
31+
new ObjectType('Symfony\Component\BrowserKit\AbstractBrowser'),
32+
new NullType(),
33+
]),
34+
);
2635
}
2736

2837
return new ObjectType('Symfony\Component\BrowserKit\AbstractBrowser');

tests/Type/Symfony/data/browserkit_assertion_trait.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
class Foo {
1010
use BrowserKitAssertionsTrait;
1111

12-
public function test(AbstractBrowser $browser, ?AbstractBrowser $nullableBrowser, mixed $mixed)
12+
/**
13+
* @param mixed $mixed
14+
*/
15+
public function test(AbstractBrowser $browser, ?AbstractBrowser $nullableBrowser, $mixed)
1316
{
1417
assertType('Symfony\Component\BrowserKit\AbstractBrowser', $this->getClient());
1518
assertType('null', $this->getClient(null));

0 commit comments

Comments
 (0)