Skip to content

Commit e4769e0

Browse files
committed
Updated with constant types, removed obsolete test (mocks don't work)
1 parent c98d81d commit e4769e0

File tree

3 files changed

+11
-283
lines changed

3 files changed

+11
-283
lines changed

src/Type/Doctrine/EntityManagerFindDynamicReturnTypeExtension.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\Constant\ConstantStringType;
89
use PHPStan\Type\MixedType;
910
use PHPStan\Type\ObjectType;
1011
use PHPStan\Type\Type;
@@ -37,27 +38,13 @@ public function getTypeFromMethodCall(
3738
if (count($methodCall->args) === 0) {
3839
return $mixedType;
3940
}
40-
$arg = $methodCall->args[0]->value;
41-
if (!($arg instanceof \PhpParser\Node\Expr\ClassConstFetch)) {
41+
$argType = $scope->getType($methodCall->args[0]->value);
42+
var_dump($argType);
43+
if (!$argType instanceof ConstantStringType) {
4244
return $mixedType;
4345
}
4446

45-
$class = $arg->class;
46-
if (!($class instanceof \PhpParser\Node\Name)) {
47-
return $mixedType;
48-
}
49-
50-
$class = (string) $class;
51-
52-
if ($class === 'static') {
53-
return $mixedType;
54-
}
55-
56-
if ($class === 'self') {
57-
$class = $scope->getClassReflection()->getName();
58-
}
59-
60-
$type = new ObjectType($class);
47+
$type = new ObjectType($argType->getValue());
6148
if ($methodReflection->getName() === 'find') {
6249
$type = TypeCombinator::addNull($type);
6350
}

src/Type/Doctrine/EntityManagerGetRepositoryDynamicReturnTypeExtension.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use PhpParser\Node\Expr\MethodCall;
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Reflection\MethodReflection;
8+
use PHPStan\Type\Constant\ConstantStringType;
9+
use PHPStan\Type\MixedType;
810
use PHPStan\Type\Type;
911

1012
class EntityManagerGetRepositoryDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension
@@ -39,26 +41,12 @@ public function getTypeFromMethodCall(
3941
if (count($methodCall->args) === 0) {
4042
return $methodReflection->getReturnType();
4143
}
42-
$arg = $methodCall->args[0]->value;
43-
if (!($arg instanceof \PhpParser\Node\Expr\ClassConstFetch)) {
44-
return $methodReflection->getReturnType();
45-
}
46-
47-
$class = $arg->class;
48-
if (!($class instanceof \PhpParser\Node\Name)) {
49-
return $methodReflection->getReturnType();
50-
}
51-
52-
$class = (string) $class;
53-
if ($class === 'static') {
54-
return $methodReflection->getReturnType();
55-
}
56-
57-
if ($class === 'self') {
58-
$class = $scope->getClassReflection()->getName();
44+
$argType = $scope->getType($methodCall->args[0]->value);
45+
if (!$argType instanceof ConstantStringType) {
46+
return new MixedType();
5947
}
6048

61-
return new EntityRepositoryType($class, $this->repositoryClass);
49+
return new EntityRepositoryType($argType->getValue(), $this->repositoryClass);
6250
}
6351

6452
}

tests/PHPStan/Type/Doctrine/EntityManagerFindDynamicReturnTypeExtensionTest.php

Lines changed: 0 additions & 247 deletions
This file was deleted.

0 commit comments

Comments
 (0)