Conditions | 10 |
Paths | 21 |
Total Lines | 57 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
79 | public function loadMetadataForAction($controllerClassName, $actionMethod) |
||
80 | { |
||
81 | $key = $controllerClassName . '_' . $actionMethod; |
||
82 | if (array_key_exists($key, $this->classAnnotations)) { |
||
83 | return $this->classAnnotations[$key]; |
||
84 | } |
||
85 | |||
86 | $r = new \ReflectionClass($controllerClassName); |
||
87 | $rMethod = $r->getMethod($actionMethod); |
||
88 | |||
89 | $metadata = new Metadata(); |
||
90 | |||
91 | |||
92 | /** @var Annotation\WorkflowDispatch|null $workflowDispatchAnnotation */ |
||
93 | $workflowDispatchAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\WorkflowDispatch::class); |
||
94 | if (null !== $workflowDispatchAnnotation) { |
||
95 | $metadata->setWorkflowDispatch($workflowDispatchAnnotation->enabled); |
||
96 | $metadata->setWorkflowRunType($workflowDispatchAnnotation->activity); |
||
97 | } |
||
98 | |||
99 | /** @var Annotation\PrepareData|null $prepareDataAnnotation */ |
||
100 | $prepareDataAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\PrepareData::class); |
||
101 | if ($prepareDataAnnotation) { |
||
102 | $metadata->setFlagRunPrepareData($prepareDataAnnotation->enabled); |
||
103 | $metadata->setPrepareDataMethod($prepareDataAnnotation->type); |
||
104 | $metadata->setPrepareDataHandler($prepareDataAnnotation->handler); |
||
105 | } |
||
106 | |||
107 | |||
108 | /** @var Annotation\DispatchConditions|null $dispatchConditionsAnnotation */ |
||
109 | $dispatchConditionsAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\DispatchConditions::class); |
||
110 | if ($dispatchConditionsAnnotation && is_array($dispatchConditionsAnnotation->conditions) && count($dispatchConditionsAnnotation->conditions) > 0) { |
||
111 | $metadata->setFlagHasConditions(true); |
||
112 | foreach ($dispatchConditionsAnnotation->conditions as $condition) { |
||
113 | if (!$condition instanceof Condition) { |
||
114 | $errMsg = 'Invalid condition annotation'; |
||
115 | throw new Exception\AnnotationReaderException($errMsg); |
||
116 | } |
||
117 | $conditionMetadata = new DispatchConditionMetadata($condition->type, $condition->handler, $condition->params); |
||
118 | |||
119 | $metadata->addConditions($conditionMetadata); |
||
120 | } |
||
121 | } |
||
122 | |||
123 | /** @var Annotation\WorkflowRouterMap|null $workflowRouterMapAnnotation */ |
||
124 | $workflowRouterMapAnnotation = $this->getReader()->getMethodAnnotation($rMethod, Annotation\WorkflowRouterMap::class); |
||
125 | if ($workflowRouterMapAnnotation) { |
||
126 | $metadata->setWorkflowManagerNameRouterParam($workflowRouterMapAnnotation->managerName); |
||
127 | $metadata->setWorkflowActionNameRouterParam($workflowRouterMapAnnotation->actionName); |
||
128 | $metadata->setWorkflowNameRouterParam($workflowRouterMapAnnotation->name); |
||
129 | $metadata->setEntryIdRouterParam($workflowRouterMapAnnotation->entryId); |
||
130 | } |
||
131 | |||
132 | $metadata->validate(); |
||
133 | |||
134 | return $metadata; |
||
135 | } |
||
136 | |||
163 |