| Conditions | 11 |
| Paths | 14 |
| Total Lines | 45 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 73 | public function dispatchScopeHooks(HookScope $scope) |
||
| 74 | { |
||
| 75 | $results = array(); |
||
| 76 | foreach ($this->repository->getScopeHooks($scope) as $hook) { |
||
| 77 | /** @var \ReflectionMethod $function */ |
||
| 78 | $function = $hook->getReflection(); |
||
| 79 | |||
| 80 | // No `@ScenarioStateArgument` annotation found |
||
| 81 | if (null === $this->reader->getMethodAnnotation($function, ScenarioStateArgument::class)) { |
||
| 82 | $results[] = $this->callCenter->makeCall(new HookCall($scope, $hook)); |
||
| 83 | continue; |
||
| 84 | } |
||
| 85 | |||
| 86 | $paramsKeys = array_map(function($element) { |
||
| 87 | return $element->name; |
||
| 88 | }, $function->getParameters()); |
||
| 89 | $store = $this->store->getStore(); |
||
| 90 | $params = $arguments = []; |
||
| 91 | |||
| 92 | // Prepare arguments from annotations |
||
| 93 | /** @var ScenarioStateArgument[] $annotations */ |
||
| 94 | $annotations = $this->reader->getMethodAnnotations($function); |
||
| 95 | foreach ($annotations as $annotation) { |
||
| 96 | if ($annotation instanceof ScenarioStateArgument && |
||
| 97 | in_array($annotation->getArgument(), $paramsKeys) && |
||
| 98 | $store->hasStateFragment($annotation->getName()) |
||
| 99 | ) { |
||
| 100 | $params[$annotation->getArgument()] = $store->getStateFragment($annotation->getName()); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | // Manage `scope` argument |
||
| 105 | foreach ($function->getParameters() as $parameter) { |
||
| 106 | if (null !== $parameter->getClass() && get_class($scope) === $parameter->getClass()->getName()) { |
||
|
|
|||
| 107 | $arguments[$parameter->getName()] = $scope; |
||
| 108 | } elseif (isset($params[$parameter->getName()])) { |
||
| 109 | $arguments[$parameter->getName()] = $params[$parameter->getName()]; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | $results[] = $this->callCenter->makeCall(new EnvironmentCall($scope->getEnvironment(), $hook, $arguments)); |
||
| 114 | } |
||
| 115 | |||
| 116 | return new CallResults($results); |
||
| 117 | } |
||
| 118 | } |
||
| 119 |