| Conditions | 21 |
| Paths | 2520 |
| Total Lines | 81 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 1 | 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 |
||
| 23 | public function build(View $view, EntityManager $em = null, $updatePage = true) |
||
|
|
|||
| 24 | { |
||
| 25 | $widgetMaps = $view->getWidgetMaps()->toArray(); |
||
| 26 | $template = clone $view; |
||
| 27 | $builtWidgetMap = []; |
||
| 28 | |||
| 29 | while (null !== $template = $template->getTemplate()) { |
||
| 30 | foreach ($template->getWidgetMaps()->toArray() as $item) { |
||
| 31 | $widgetMaps[] = $item; |
||
| 32 | } |
||
| 33 | } |
||
| 34 | |||
| 35 | $slots = []; |
||
| 36 | /** @var WidgetMap $widgetMapItem */ |
||
| 37 | foreach ($widgetMaps as $widgetMapItem) { |
||
| 38 | $id = $widgetMapItem->getId(); |
||
| 39 | if ($widgetMapItem->getReplaced()) { |
||
| 40 | $id = $widgetMapItem->getReplaced()->getId(); |
||
| 41 | } |
||
| 42 | if (empty($slots[$widgetMapItem->getSlot()][$id]) |
||
| 43 | || !empty($slots[$widgetMapItem->getSlot()][$id]) |
||
| 44 | && $widgetMapItem->getAction() !== WidgetMap::ACTION_CREATE) { |
||
| 45 | $slots[$widgetMapItem->getSlot()][$id] = $widgetMapItem; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | foreach ($slots as $slot => $widgetMaps) { |
||
| 50 | foreach ($widgetMaps as $key => $widgetMap) { |
||
| 51 | if ($widgetMap->getAction() == WidgetMap::ACTION_DELETE) { |
||
| 52 | unset($slots[$slot][$key]); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | foreach ($slots as $slot => $widgetMaps) { |
||
| 58 | $mainWidgetMap = null; |
||
| 59 | $builtWidgetMap[$slot] = []; |
||
| 60 | |||
| 61 | /** @var WidgetMap $_widgetMap */ |
||
| 62 | foreach ($widgetMaps as $_widgetMap) { |
||
| 63 | if (!$_widgetMap->getParent()) { |
||
| 64 | $mainWidgetMap = $_widgetMap; |
||
| 65 | break; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | if ($mainWidgetMap) { |
||
| 70 | $builtWidgetMap[$slot][] = $mainWidgetMap; |
||
| 71 | /* |
||
| 72 | * @param WidgetMap $currentWidgetMap |
||
| 73 | */ |
||
| 74 | $orderizeWidgetMap = function ($currentWidgetMap, $builtWidgetMap) use ($slot, &$orderizeWidgetMap, $widgetMaps, $view) { |
||
| 75 | $children = $currentWidgetMap->getChildren($view); |
||
| 76 | foreach ($children as $child) { |
||
| 77 | if (in_array($child, $widgetMaps) |
||
| 78 | ) { |
||
| 79 | $offset = array_search($currentWidgetMap, $builtWidgetMap[$slot]) + ($child->getPosition() == WidgetMap::POSITION_AFTER ? 1 : 0); |
||
| 80 | array_splice($builtWidgetMap[$slot], $offset, 0, [$child]); |
||
| 81 | $builtWidgetMap = $orderizeWidgetMap($child, $builtWidgetMap); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return $builtWidgetMap; |
||
| 86 | }; |
||
| 87 | $builtWidgetMap = $orderizeWidgetMap($mainWidgetMap, $builtWidgetMap); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | $_builtWidgetMap = $builtWidgetMap; |
||
| 91 | $builtWidgetMap = []; |
||
| 92 | foreach ($_builtWidgetMap as $slot => $__builtWidgetMap) { |
||
| 93 | foreach ($__builtWidgetMap as $key => $item) { |
||
| 94 | $builtWidgetMap[$slot][$item->getWidget()->getId()] = $item; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($updatePage) { |
||
| 99 | $view->setBuiltWidgetMap($builtWidgetMap); |
||
| 100 | } |
||
| 101 | |||
| 102 | return $builtWidgetMap; |
||
| 103 | } |
||
| 104 | |||
| 134 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.