Skip to content

Commit df90a3b

Browse files
author
Bartłomiej Nowak
committed
code review fixes 2
1 parent 89c7534 commit df90a3b

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/Symfony/MessageMapFactory.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\Reflection\ClassReflection;
66
use PHPStan\Reflection\ReflectionProvider;
7-
use PHPStan\ShouldNotHappenException;
87
use Symfony\Component\Messenger\Handler\MessageSubscriberInterface;
98
use function class_exists;
109
use function count;
@@ -96,14 +95,11 @@ private function guessHandledMessages(ClassReflection $reflectionClass): iterabl
9695
$className = $reflectionClass->getName();
9796

9897
foreach ($className::getHandledMessages() as $index => $value) {
99-
try {
100-
if (self::containOptions($index, $value)) {
101-
yield $index => $value;
102-
} else {
103-
yield $value => ['method' => self::DEFAULT_HANDLER_METHOD];
104-
}
105-
} catch (ShouldNotHappenException $e) {
106-
continue;
98+
$containOptions = self::containOptions($index, $value);
99+
if ($containOptions === true) {
100+
yield $index => $value;
101+
} elseif ($containOptions === false) {
102+
yield $value => ['method' => self::DEFAULT_HANDLER_METHOD];
107103
}
108104
}
109105

@@ -144,15 +140,15 @@ private function guessHandledMessages(ClassReflection $reflectionClass): iterabl
144140
* @phpstan-assert-if-false =int $index
145141
* @phpstan-assert-if-false =class-string $value
146142
*/
147-
private static function containOptions($index, $value): bool
143+
private static function containOptions($index, $value): ?bool
148144
{
149145
if (is_string($index) && class_exists($index) && is_array($value)) {
150146
return true;
151147
} elseif (is_int($index) && is_string($value) && class_exists($value)) {
152148
return false;
153149
}
154150

155-
throw new ShouldNotHappenException();
151+
return null;
156152
}
157153

158154
}

src/Type/Symfony/MessengerHandleTraitReturnTypeExtension.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public function __construct(MessageMapFactory $symfonyMessageMapFactory)
3333
public function getType(Expr $expr, Scope $scope): ?Type
3434
{
3535
if ($this->isSupported($expr, $scope)) {
36-
$arg = $expr->getArgs()[0]->value;
36+
$args = $expr->getArgs();
37+
if (count($args) !== 1) {
38+
return null;
39+
}
40+
41+
$arg = $args[0]->value;
3742
$argClassNames = $scope->getType($arg)->getObjectClassNames();
3843

3944
if (count($argClassNames) === 1) {

0 commit comments

Comments
 (0)