| Conditions | 5 |
| Paths | 5 |
| Total Lines | 56 |
| Code Lines | 34 |
| 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 |
||
| 55 | public function getActionsForSubject($subject) |
||
| 56 | { |
||
| 57 | $workflows = $this->registry->all($subject); |
||
| 58 | $actions = []; |
||
| 59 | |||
| 60 | foreach ($workflows as $workflow) { |
||
| 61 | /** @var Transition $transition */ |
||
| 62 | foreach ($workflow->getEnabledTransitions($subject) as $transition) { |
||
| 63 | $transitionMeta = $workflow->getMetadataStore()->getTransitionMetadata($transition); |
||
| 64 | |||
| 65 | $blockers = $workflow->buildTransitionBlockerList($subject, $transition->getName()); |
||
| 66 | |||
| 67 | $url = sprintf( |
||
| 68 | '%s?%s', |
||
| 69 | $this->iriConverter->getIriFromItem($subject, UrlGeneratorInterface::ABS_URL), |
||
| 70 | http_build_query([ |
||
| 71 | 'workflow' => $workflow->getName(), |
||
| 72 | 'transition' => $transition->getName(), |
||
| 73 | ]) |
||
| 74 | ); |
||
| 75 | |||
| 76 | $entryPoint = new EntryPoint(); |
||
| 77 | $entryPoint->setUrl($url); |
||
| 78 | $entryPoint->setHttpMethod('PATCH'); |
||
| 79 | |||
| 80 | $currentAction = new Action(); |
||
| 81 | $currentAction->setTarget($entryPoint); |
||
| 82 | $currentAction->setName($transition->getName()); |
||
| 83 | $currentAction->setDescription($transitionMeta['description'] ?? ucfirst($transition->getName()).' Action'); |
||
| 84 | // @TODO: add sub status (available, unavailable, access denied, invalid) |
||
| 85 | |||
| 86 | foreach ($blockers as $blocker) { |
||
| 87 | $parameters = $blocker->getParameters(); |
||
| 88 | |||
| 89 | if (array_key_exists('original_violation', $parameters)) { |
||
| 90 | $violation = $parameters['original_violation']; |
||
| 91 | } else { |
||
| 92 | // @TODO: add a factory or event for building Violations from TransitionBlockers |
||
| 93 | $violation = new ConstraintViolation( |
||
| 94 | $blocker->getMessage(), |
||
| 95 | $blocker->getMessage(), |
||
| 96 | $blocker->getParameters(), |
||
| 97 | $subject, |
||
| 98 | '/', |
||
| 99 | '' |
||
| 100 | ); |
||
| 101 | } |
||
| 102 | |||
| 103 | $currentAction->addError($violation); |
||
| 104 | } |
||
| 105 | |||
| 106 | $actions[] = $currentAction; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | return $actions; |
||
| 111 | } |
||
| 113 |