Skip to content

Commit d50062e

Browse files
Rework
1 parent c7e1125 commit d50062e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/Type/Symfony/BrowserKitAssertionTraitReturnTypeExtension.php

Lines changed: 6 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,23 @@ 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());
5757

58+
$reflectionClass = $methodReflection->getDeclaringClass()->getNativeReflection();
5859
if (!$reflectionClass->hasMethod(self::TRAIT_METHOD_NAME)) {
5960
return false;
6061
}
6162

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

6566
return $declaringClassReflection->getName() === self::TRAIT_NAME;
6667
}

src/Type/Symfony/MessengerHandleTraitReturnTypeExtension.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,23 @@ 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());
7878

79+
$reflectionClass = $methodReflection->getDeclaringClass()->getNativeReflection();
7980
if (!$reflectionClass->hasMethod(self::TRAIT_METHOD_NAME)) {
8081
return false;
8182
}
8283

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

8687
return $declaringClassReflection->getName() === self::TRAIT_NAME;
8788
}

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)