Conditions | 13 |
Paths | 6 |
Total Lines | 59 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
69 | public function onMetadataWorkflowToRun(WorkflowDispatchEventInterface $e) |
||
70 | { |
||
71 | $mvcEvent = $e->getMvcEvent(); |
||
72 | $controller = $mvcEvent->getTarget(); |
||
73 | if (!$controller instanceof AbstractController) { |
||
74 | return null; |
||
75 | } |
||
76 | |||
77 | $routeMatch = $mvcEvent->getRouteMatch(); |
||
78 | if (!$routeMatch) { |
||
79 | return null; |
||
80 | } |
||
81 | |||
82 | $action = $routeMatch->getParam('action', 'not-found'); |
||
83 | $actionMethod = AbstractController::getMethodFromAction($action); |
||
84 | |||
85 | if (!method_exists($controller, $actionMethod)) { |
||
86 | return null; |
||
87 | } |
||
88 | |||
89 | $controllerClassName = get_class($controller); |
||
90 | |||
91 | $metadata = $this->getMetadataReader()->loadMetadataForAction($controllerClassName, $actionMethod); |
||
92 | |||
93 | if (!$metadata instanceof MetadataInterface) { |
||
94 | $errMsg = sprintf('Metadata not implement %s', MetadataInterface::class); |
||
95 | throw new Exception\InvalidMetadataException($errMsg); |
||
96 | } |
||
97 | |||
98 | $workflowManagerNameParam = $metadata->getWorkflowManagerNameRouterParam(); |
||
99 | $workflowManagerName = $routeMatch->getParam($workflowManagerNameParam, null); |
||
100 | |||
101 | $workflowActionNameParam = $metadata->getWorkflowActionNameRouterParam(); |
||
102 | $workflowActionName = $routeMatch->getParam($workflowActionNameParam, null); |
||
103 | |||
104 | $workflowNameParam = $metadata->getWorkflowNameRouterParam(); |
||
105 | $workflowName = $routeMatch->getParam($workflowNameParam, null); |
||
106 | |||
107 | $entryIdParam = $metadata->getEntryIdRouterParam(); |
||
108 | $entryId = $routeMatch->getParam($entryIdParam, null); |
||
109 | |||
110 | |||
111 | $runType = $e->getMetadata()->getWorkflowRunType(); |
||
112 | if (null !== $workflowManagerName && null !== $workflowActionName |
||
113 | && ((RunWorkflowParam::WORKFLOW_RUN_INITIALIZE === $runType && null !== $workflowName && null === $entryId) |
||
114 | ||(RunWorkflowParam::WORKFLOW_RUN_TYPE_DO_ACTION === $runType && null !== $entryId && null === $workflowName)) |
||
115 | ) { |
||
116 | $runWorkflowParam = new RunWorkflowParam(); |
||
117 | $runWorkflowParam->setRunType($runType); |
||
118 | $runWorkflowParam->setManagerName($workflowManagerName); |
||
119 | $runWorkflowParam->setActionName($workflowActionName); |
||
120 | $runWorkflowParam->setEntryId($entryId); |
||
121 | $runWorkflowParam->setWorkflowName($workflowName); |
||
122 | |||
123 | return $runWorkflowParam; |
||
124 | } |
||
125 | |||
126 | return null; |
||
127 | } |
||
128 | |||
149 |