|
3 | 3 | namespace PHPStan\Symfony; |
4 | 4 |
|
5 | 5 | use PHPStan\Reflection\ClassReflection; |
| 6 | +use PHPStan\Reflection\MissingMethodFromReflectionException; |
6 | 7 | use PHPStan\Reflection\ParametersAcceptorSelector; |
7 | 8 | use PHPStan\Reflection\ReflectionProvider; |
8 | | -use RuntimeException; |
9 | 9 | use Symfony\Component\Messenger\Handler\MessageSubscriberInterface; |
10 | 10 | use function count; |
11 | 11 | use function is_int; |
12 | 12 | use function is_null; |
13 | 13 | use function is_string; |
14 | 14 |
|
15 | | -// todo add tests |
16 | 15 | final class MessageMapFactory |
17 | 16 | { |
18 | 17 |
|
@@ -94,23 +93,30 @@ private function guessHandledMessages(ClassReflection $reflectionClass): iterabl |
94 | 93 | return; |
95 | 94 | } |
96 | 95 |
|
97 | | - // todo handle if doesn't exists |
98 | | - $methodReflection = $reflectionClass->getNativeMethod(self::DEFAULT_HANDLER_METHOD); |
| 96 | + try { |
| 97 | + $methodReflection = $reflectionClass->getNativeMethod(self::DEFAULT_HANDLER_METHOD); |
| 98 | + } catch (MissingMethodFromReflectionException $e) { |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + $variants = $methodReflection->getVariants(); |
| 103 | + if (count($variants) !== 1) { |
| 104 | + return; |
| 105 | + } |
99 | 106 |
|
100 | | - $variant = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); |
101 | | - $parameters = $variant->getParameters(); |
| 107 | + $parameters = $variants[0]->getParameters(); |
102 | 108 |
|
103 | 109 | if (count($parameters) !== 1) { |
104 | | - // todo handle error |
105 | | - throw new RuntimeException('invalid handler'); |
| 110 | + return; |
106 | 111 | } |
107 | 112 |
|
108 | | - $type = $parameters[0]->getType(); |
| 113 | + $classNames = $parameters[0]->getType()->getObjectClassNames(); |
109 | 114 |
|
110 | | - // todo many class names? |
111 | | - foreach ($type->getObjectClassNames() as $className) { |
112 | | - yield $className => ['method' => self::DEFAULT_HANDLER_METHOD]; |
| 115 | + if (count($classNames) !== 1) { |
| 116 | + return; |
113 | 117 | } |
| 118 | + |
| 119 | + yield $classNames[0] => ['method' => self::DEFAULT_HANDLER_METHOD]; |
114 | 120 | } |
115 | 121 |
|
116 | 122 | } |
0 commit comments