|
5 | 5 | use Drupal;
|
6 | 6 | use mglaman\PHPStanDrupal\Drupal\DrupalServiceDefinition;
|
7 | 7 | use mglaman\PHPStanDrupal\Drupal\ServiceMap;
|
| 8 | +use PhpParser\Node\Expr\ClassConstFetch; |
8 | 9 | use PhpParser\Node\Expr\StaticCall;
|
| 10 | +use PhpParser\Node\Name\FullyQualified; |
9 | 11 | use PhpParser\Node\Scalar\String_;
|
10 | 12 | use PhpParser\Node\VariadicPlaceholder;
|
11 | 13 | use PHPStan\Analyser\Scope;
|
@@ -51,17 +53,29 @@ public function getTypeFromStaticMethodCall(
|
51 | 53 | if ($arg1 instanceof VariadicPlaceholder) {
|
52 | 54 | throw new ShouldNotHappenException();
|
53 | 55 | }
|
| 56 | + |
54 | 57 | $arg1 = $arg1->value;
|
55 |
| - if (!$arg1 instanceof String_) { |
56 |
| - // @todo determine what these types are. |
57 |
| - return $returnType; |
| 58 | + |
| 59 | + if ($arg1 instanceof String_) { |
| 60 | + $serviceId = $arg1->value; |
| 61 | + return $this->getServiceType($serviceId) ?? $returnType; |
58 | 62 | }
|
59 | 63 |
|
60 |
| - $serviceId = $arg1->value; |
| 64 | + if ($arg1 instanceof ClassConstFetch && $arg1->class instanceof FullyQualified) { |
| 65 | + $serviceId = (string) $arg1->class; |
| 66 | + return $this->getServiceType($serviceId) ?? $returnType; |
| 67 | + } |
| 68 | + |
| 69 | + return $returnType; |
| 70 | + } |
| 71 | + |
| 72 | + protected function getServiceType(string $serviceId): ?Type |
| 73 | + { |
61 | 74 | $service = $this->serviceMap->getService($serviceId);
|
62 | 75 | if ($service instanceof DrupalServiceDefinition) {
|
63 | 76 | return $service->getType();
|
64 | 77 | }
|
65 |
| - return $returnType; |
| 78 | + |
| 79 | + return null; |
66 | 80 | }
|
67 | 81 | }
|
0 commit comments