Skip to content

Commit 46b4f00

Browse files
authored
Merge pull request #93 from localheinz/feature/clean-up
Enhancement: Slightly clean up code
2 parents defdf4d + f4852d0 commit 46b4f00

3 files changed

+31
-28
lines changed

src/Extension/ObjectProphecyRevealDynamicReturnTypeExtension.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,21 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2626

2727
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
2828
{
29+
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
30+
2931
$calledOnType = $scope->getType($methodCall->var);
3032

31-
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
33+
$returnType = $parametersAcceptor->getReturnType();
3234

3335
if (!$calledOnType instanceof ObjectProphecyType) {
34-
return $parametersAcceptor->getReturnType();
36+
return $returnType;
3537
}
3638

3739
$types = \array_map(static function (string $class): ObjectType {
3840
return new ObjectType($class);
3941
}, $calledOnType->getProphesizedClasses());
4042

41-
$types[] = $parametersAcceptor->getReturnType();
43+
$types[] = $returnType;
4244

4345
return TypeCombinator::intersect(...$types);
4446
}

src/Extension/ObjectProphecyWillImplementDynamicReturnTypeExtension.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,37 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
3131

3232
$calledOnType = $scope->getType($methodCall->var);
3333

34-
$prophecyType = $parametersAcceptor->getReturnType();
34+
$returnType = $parametersAcceptor->getReturnType();
3535

3636
if (!$calledOnType instanceof ObjectProphecyType) {
37-
return $prophecyType;
37+
return $returnType;
3838
}
3939

4040
if (0 === \count($methodCall->args)) {
41-
return $prophecyType;
41+
return $returnType;
4242
}
4343

44-
$argType = $scope->getType($methodCall->args[0]->value);
44+
$argumentType = $scope->getType($methodCall->args[0]->value);
4545

46-
if (!($argType instanceof ConstantStringType)) {
47-
return $prophecyType;
46+
if (!$argumentType instanceof ConstantStringType) {
47+
return $returnType;
4848
}
4949

50-
$class = $argType->getValue();
50+
$className = $argumentType->getValue();
5151

52-
if (!($prophecyType instanceof TypeWithClassName)) {
52+
if (!$returnType instanceof TypeWithClassName) {
5353
throw new ShouldNotHappenException();
5454
}
5555

56-
if ('static' === $class) {
57-
return $prophecyType;
56+
if ('static' === $className) {
57+
return $returnType;
5858
}
5959

60-
if ('self' === $class && null !== $scope->getClassReflection()) {
61-
$class = $scope->getClassReflection()->getName();
60+
if ('self' === $className && null !== $scope->getClassReflection()) {
61+
$className = $scope->getClassReflection()->getName();
6262
}
6363

64-
$calledOnType->addProphesizedClass($class);
64+
$calledOnType->addProphesizedClass($className);
6565

6666
return $calledOnType;
6767
}

src/Extension/ProphetProphesizeDynamicReturnTypeExtension.php

+13-12
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,33 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3535
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3636
{
3737
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants());
38-
$prophecyType = $parametersAcceptor->getReturnType();
38+
39+
$returnType = $parametersAcceptor->getReturnType();
3940

4041
if (0 === \count($methodCall->args)) {
41-
return $prophecyType;
42+
return $returnType;
4243
}
4344

44-
$argType = $scope->getType($methodCall->args[0]->value);
45+
$argumentType = $scope->getType($methodCall->args[0]->value);
4546

46-
if (!($argType instanceof ConstantStringType)) {
47-
return $prophecyType;
47+
if (!$argumentType instanceof ConstantStringType) {
48+
return $returnType;
4849
}
4950

50-
$class = $argType->getValue();
51+
$className = $argumentType->getValue();
5152

52-
if (!($prophecyType instanceof TypeWithClassName)) {
53+
if (!$returnType instanceof TypeWithClassName) {
5354
throw new ShouldNotHappenException();
5455
}
5556

56-
if ('static' === $class) {
57-
return $prophecyType;
57+
if ('static' === $className) {
58+
return $returnType;
5859
}
5960

60-
if ('self' === $class && null !== $scope->getClassReflection()) {
61-
$class = $scope->getClassReflection()->getName();
61+
if ('self' === $className && null !== $scope->getClassReflection()) {
62+
$className = $scope->getClassReflection()->getName();
6263
}
6364

64-
return new ObjectProphecyType($class);
65+
return new ObjectProphecyType($className);
6566
}
6667
}

0 commit comments

Comments
 (0)