Skip to content

Commit 50162c7

Browse files
committed
matching() returns the same type it was called on
1 parent 825a1a1 commit 50162c7

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"prefer-stable": true,
77
"require": {
88
"php": "~7.0",
9-
"phpstan/phpstan": "^0.6",
9+
"phpstan/phpstan": "^0.6.3",
1010
"doctrine/common": "^2.7",
1111
"doctrine/orm": "^2.5"
1212
},

extension.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ services:
33
class: PHPStan\Reflection\Doctrine\DoctrineSelectableClassReflectionExtension
44
tags:
55
- phpstan.broker.methodsClassReflectionExtension
6+
-
7+
class: PHPStan\Type\Doctrine\DoctrineSelectableDynamicReturnTypeExtension
8+
tags:
9+
- phpstan.broker.dynamicMethodReturnTypeExtension
610
-
711
class: PHPStan\Type\Doctrine\EntityManagerFindDynamicReturnTypeExtension
812
tags:
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Type\Doctrine;
4+
5+
use PhpParser\Node\Expr\MethodCall;
6+
use PHPStan\Analyser\Scope;
7+
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\Type;
9+
10+
class DoctrineSelectableDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension
11+
{
12+
13+
public static function getClass(): string
14+
{
15+
return \Doctrine\Common\Collections\Collection::class;
16+
}
17+
18+
public function isMethodSupported(MethodReflection $methodReflection): bool
19+
{
20+
return $methodReflection->getName() === 'matching';
21+
}
22+
23+
public function getTypeFromMethodCall(
24+
MethodReflection $methodReflection,
25+
MethodCall $methodCall,
26+
Scope $scope
27+
): Type
28+
{
29+
return $scope->getType($methodCall->var);
30+
}
31+
32+
}

0 commit comments

Comments
 (0)