Skip to content

Commit 9a6e442

Browse files
Rework
1 parent c7e1125 commit 9a6e442

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

β€Žsrc/Type/Symfony/BrowserKitAssertionTraitReturnTypeExtension.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class BrowserKitAssertionTraitReturnTypeExtension implements ExpressionTyp
1818
{
1919

2020
private const TRAIT_NAME = 'Symfony\Bundle\FrameworkBundle\Test\BrowserKitAssertionsTrait';
21-
private const TRAIT_METHOD_NAME = 'getClient';
21+
private const TRAIT_METHOD_NAME = 'getclient';
2222

2323
public function getType(Expr $expr, Scope $scope): ?Type
2424
{
@@ -45,22 +45,26 @@ public function getType(Expr $expr, Scope $scope): ?Type
4545
*/
4646
private function isSupported(Expr $expr, Scope $scope): bool
4747
{
48-
if (!($expr instanceof MethodCall) || !($expr->name instanceof Identifier) || $expr->name->name !== self::TRAIT_METHOD_NAME) {
48+
if (!($expr instanceof MethodCall) || !($expr->name instanceof Identifier) || $expr->name->toLowerString() !== self::TRAIT_METHOD_NAME) {
4949
return false;
5050
}
5151

5252
if (!$scope->isInClass()) {
5353
return false;
5454
}
5555

56-
$reflectionClass = $scope->getClassReflection()->getNativeReflection();
56+
$methodReflection = $scope->getMethodReflection($scope->getType($expr->var), $expr->name->toString());
57+
if (null === $methodReflection) {
58+
return false;
59+
}
5760

61+
$reflectionClass = $methodReflection->getDeclaringClass()->getNativeReflection();
5862
if (!$reflectionClass->hasMethod(self::TRAIT_METHOD_NAME)) {
5963
return false;
6064
}
6165

62-
$methodReflection = $reflectionClass->getMethod(self::TRAIT_METHOD_NAME);
63-
$declaringClassReflection = $methodReflection->getBetterReflection()->getDeclaringClass();
66+
$traitMethodReflection = $reflectionClass->getMethod(self::TRAIT_METHOD_NAME);
67+
$declaringClassReflection = $traitMethodReflection->getBetterReflection()->getDeclaringClass();
6468

6569
return $declaringClassReflection->getName() === self::TRAIT_NAME;
6670
}

β€Žsrc/Type/Symfony/MessengerHandleTraitReturnTypeExtension.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,26 @@ private function getMessageMap(): MessageMap
6666
*/
6767
private function isSupported(Expr $expr, Scope $scope): bool
6868
{
69-
if (!($expr instanceof MethodCall) || !($expr->name instanceof Identifier) || $expr->name->name !== self::TRAIT_METHOD_NAME) {
69+
if (!($expr instanceof MethodCall) || !($expr->name instanceof Identifier) || $expr->name->toLowerString() !== self::TRAIT_METHOD_NAME) {
7070
return false;
7171
}
7272

7373
if (!$scope->isInClass()) {
7474
return false;
7575
}
7676

77-
$reflectionClass = $scope->getClassReflection()->getNativeReflection();
77+
$methodReflection = $scope->getMethodReflection($scope->getType($expr->var), $expr->name->toString());
78+
if (null === $methodReflection) {
79+
return false;
80+
}
7881

82+
$reflectionClass = $methodReflection->getDeclaringClass()->getNativeReflection();
7983
if (!$reflectionClass->hasMethod(self::TRAIT_METHOD_NAME)) {
8084
return false;
8185
}
8286

83-
$methodReflection = $reflectionClass->getMethod(self::TRAIT_METHOD_NAME);
84-
$declaringClassReflection = $methodReflection->getBetterReflection()->getDeclaringClass();
87+
$traitMethodReflection = $reflectionClass->getMethod(self::TRAIT_METHOD_NAME);
88+
$declaringClassReflection = $traitMethodReflection->getBetterReflection()->getDeclaringClass();
8589

8690
return $declaringClassReflection->getName() === self::TRAIT_NAME;
8791
}

β€Žtests/Type/Symfony/data/browserkit_assertion_trait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ public function test(AbstractBrowser $browser, ?AbstractBrowser $nullableBrowser
1919
assertType('Symfony\Component\BrowserKit\AbstractBrowser', $this->getClient($browser));
2020
assertType('Symfony\Component\BrowserKit\AbstractBrowser|null', $this->getClient($nullableBrowser));
2121
assertType('Symfony\Component\BrowserKit\AbstractBrowser|null', $this->getClient($mixed));
22+
23+
assertType('Symfony\Component\BrowserKit\AbstractBrowser', $this->getclient());
24+
assertType('mixed', $mixed->getClient());
2225
}
2326
}

0 commit comments

Comments
 (0)