| Conditions | 10 |
| Paths | 14 |
| Total Lines | 43 |
| Code Lines | 25 |
| 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 namespace Anomaly\Streams\Platform\Ui\ControlPanel\Component\Button\Guesser; |
||
| 59 | public function guess(ControlPanelBuilder $builder) |
||
| 60 | { |
||
| 61 | $buttons = $builder->getButtons(); |
||
| 62 | $sections = $builder->getControlPanelSections(); |
||
| 63 | |||
| 64 | $active = $sections->active(); |
||
| 65 | $module = $this->modules->active(); |
||
| 66 | |||
| 67 | foreach ($buttons as &$button) { |
||
| 68 | |||
| 69 | // If we already have an HREF then skip it. |
||
| 70 | if (isset($button['attributes']['href'])) { |
||
| 71 | continue; |
||
| 72 | } |
||
| 73 | |||
| 74 | // Determine the HREF based on the button type. |
||
| 75 | switch (array_get($button, 'button')) { |
||
| 76 | |||
| 77 | case 'add': |
||
| 78 | case 'new': |
||
| 79 | case 'create': |
||
| 80 | $button['attributes']['href'] = $active->getHref('create'); |
||
| 81 | break; |
||
| 82 | |||
| 83 | case 'export': |
||
| 84 | if ($module) { |
||
| 85 | $button['attributes']['href'] = $this->url->to( |
||
| 86 | 'entry/handle/export/' . $module->getNamespace() . '/' . array_get( |
||
| 87 | $button, |
||
| 88 | 'namespace' |
||
| 89 | ) . '/' . array_get($button, 'stream') |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | |||
| 95 | if (!isset($button['attributes']['href']) && isset($button['button'])) { |
||
| 96 | $button['attributes']['href'] = $active->getHref($button['button']); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | $builder->setButtons($buttons); |
||
| 101 | } |
||
| 102 | } |
||
| 103 |