From f4852d06582097fce1b44bfb9201359819caf92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 28 Dec 2019 00:18:27 +0100 Subject: [PATCH] Enhancement: Slightly clean up code --- ...ophecyRevealDynamicReturnTypeExtension.php | 8 +++--- ...illImplementDynamicReturnTypeExtension.php | 26 +++++++++---------- ...etProphesizeDynamicReturnTypeExtension.php | 25 +++++++++--------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/Extension/ObjectProphecyRevealDynamicReturnTypeExtension.php b/src/Extension/ObjectProphecyRevealDynamicReturnTypeExtension.php index 3a4a336..0edb7c0 100644 --- a/src/Extension/ObjectProphecyRevealDynamicReturnTypeExtension.php +++ b/src/Extension/ObjectProphecyRevealDynamicReturnTypeExtension.php @@ -26,19 +26,21 @@ public function isMethodSupported(MethodReflection $methodReflection): bool public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type { + $parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); + $calledOnType = $scope->getType($methodCall->var); - $parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); + $returnType = $parametersAcceptor->getReturnType(); if (!$calledOnType instanceof ObjectProphecyType) { - return $parametersAcceptor->getReturnType(); + return $returnType; } $types = \array_map(static function (string $class): ObjectType { return new ObjectType($class); }, $calledOnType->getProphesizedClasses()); - $types[] = $parametersAcceptor->getReturnType(); + $types[] = $returnType; return TypeCombinator::intersect(...$types); } diff --git a/src/Extension/ObjectProphecyWillImplementDynamicReturnTypeExtension.php b/src/Extension/ObjectProphecyWillImplementDynamicReturnTypeExtension.php index eebcb2c..c599a2b 100644 --- a/src/Extension/ObjectProphecyWillImplementDynamicReturnTypeExtension.php +++ b/src/Extension/ObjectProphecyWillImplementDynamicReturnTypeExtension.php @@ -31,37 +31,37 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method $calledOnType = $scope->getType($methodCall->var); - $prophecyType = $parametersAcceptor->getReturnType(); + $returnType = $parametersAcceptor->getReturnType(); if (!$calledOnType instanceof ObjectProphecyType) { - return $prophecyType; + return $returnType; } if (0 === \count($methodCall->args)) { - return $prophecyType; + return $returnType; } - $argType = $scope->getType($methodCall->args[0]->value); + $argumentType = $scope->getType($methodCall->args[0]->value); - if (!($argType instanceof ConstantStringType)) { - return $prophecyType; + if (!$argumentType instanceof ConstantStringType) { + return $returnType; } - $class = $argType->getValue(); + $className = $argumentType->getValue(); - if (!($prophecyType instanceof TypeWithClassName)) { + if (!$returnType instanceof TypeWithClassName) { throw new ShouldNotHappenException(); } - if ('static' === $class) { - return $prophecyType; + if ('static' === $className) { + return $returnType; } - if ('self' === $class && null !== $scope->getClassReflection()) { - $class = $scope->getClassReflection()->getName(); + if ('self' === $className && null !== $scope->getClassReflection()) { + $className = $scope->getClassReflection()->getName(); } - $calledOnType->addProphesizedClass($class); + $calledOnType->addProphesizedClass($className); return $calledOnType; } diff --git a/src/Extension/ProphetProphesizeDynamicReturnTypeExtension.php b/src/Extension/ProphetProphesizeDynamicReturnTypeExtension.php index 89ff6c7..e89b4dc 100644 --- a/src/Extension/ProphetProphesizeDynamicReturnTypeExtension.php +++ b/src/Extension/ProphetProphesizeDynamicReturnTypeExtension.php @@ -35,32 +35,33 @@ public function isMethodSupported(MethodReflection $methodReflection): bool public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type { $parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants()); - $prophecyType = $parametersAcceptor->getReturnType(); + + $returnType = $parametersAcceptor->getReturnType(); if (0 === \count($methodCall->args)) { - return $prophecyType; + return $returnType; } - $argType = $scope->getType($methodCall->args[0]->value); + $argumentType = $scope->getType($methodCall->args[0]->value); - if (!($argType instanceof ConstantStringType)) { - return $prophecyType; + if (!$argumentType instanceof ConstantStringType) { + return $returnType; } - $class = $argType->getValue(); + $className = $argumentType->getValue(); - if (!($prophecyType instanceof TypeWithClassName)) { + if (!$returnType instanceof TypeWithClassName) { throw new ShouldNotHappenException(); } - if ('static' === $class) { - return $prophecyType; + if ('static' === $className) { + return $returnType; } - if ('self' === $class && null !== $scope->getClassReflection()) { - $class = $scope->getClassReflection()->getName(); + if ('self' === $className && null !== $scope->getClassReflection()) { + $className = $scope->getClassReflection()->getName(); } - return new ObjectProphecyType($class); + return new ObjectProphecyType($className); } }