| Conditions | 7 |
| Paths | 13 |
| Total Lines | 67 |
| Code Lines | 41 |
| 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 |
||
| 55 | public function getActionsForSubject($subject) |
||
| 56 | { |
||
| 57 | $workflows = $this->registry->all($subject); |
||
| 58 | $actions = []; |
||
| 59 | |||
| 60 | foreach ($workflows as $workflow) { |
||
| 61 | |||
| 62 | $possibleTransitions = []; |
||
| 63 | $marking = $workflow->getMarking($subject); |
||
| 64 | |||
| 65 | foreach ($workflow->getDefinition()->getTransitions() as $transition) { |
||
| 66 | $froms = array_flip($transition->getFroms()); |
||
| 67 | $intersection = array_intersect_key($froms, $marking->getPlaces()); |
||
| 68 | if ($intersection) { |
||
|
|
|||
| 69 | $possibleTransitions[] = $transition; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | foreach ($possibleTransitions as $transition) { |
||
| 74 | $transitionBlockerList = $workflow->buildTransitionBlockerList($subject, $transition->getName()); |
||
| 75 | |||
| 76 | $transitionMeta = $workflow->getMetadataStore()->getTransitionMetadata($transition); |
||
| 77 | |||
| 78 | $url = sprintf( |
||
| 79 | '%s?%s', |
||
| 80 | $this->iriConverter->getIriFromItem($subject, UrlGeneratorInterface::ABS_URL), |
||
| 81 | http_build_query([ |
||
| 82 | 'workflow' => $workflow->getName(), |
||
| 83 | 'transition' => $transition->getName(), |
||
| 84 | ]) |
||
| 85 | ); |
||
| 86 | |||
| 87 | $entryPoint = new EntryPoint(); |
||
| 88 | $entryPoint->setUrl($url); |
||
| 89 | $entryPoint->setHttpMethod('PATCH'); |
||
| 90 | |||
| 91 | $currentAction = new Action(); |
||
| 92 | $currentAction->setTarget($entryPoint); |
||
| 93 | $currentAction->setName($transition->getName()); |
||
| 94 | $currentAction->setDescription($transitionMeta['description'] ?? ucfirst($transition->getName()).' Action'); |
||
| 95 | // @TODO: add sub status (available, unavailable, access denied, invalid) |
||
| 96 | |||
| 97 | foreach ($transitionBlockerList as $blocker) { |
||
| 98 | $parameters = $blocker->getParameters(); |
||
| 99 | |||
| 100 | if (array_key_exists('original_violation', $parameters)) { |
||
| 101 | $violation = $parameters['original_violation']; |
||
| 102 | } else { |
||
| 103 | // @TODO: add a factory or event for building Violations from TransitionBlockers |
||
| 104 | $violation = new ConstraintViolation( |
||
| 105 | $blocker->getMessage(), |
||
| 106 | $blocker->getMessage(), |
||
| 107 | $blocker->getParameters(), |
||
| 108 | $subject, |
||
| 109 | '/', |
||
| 110 | '' |
||
| 111 | ); |
||
| 112 | } |
||
| 113 | |||
| 114 | $currentAction->addError($violation); |
||
| 115 | } |
||
| 116 | |||
| 117 | $actions[] = $currentAction; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | return $actions; |
||
| 122 | } |
||
| 124 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.