Conditions | 9 |
Paths | 4 |
Total Lines | 52 |
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 |
||
22 | public function process() |
||
23 | { |
||
24 | call_user_func_array($this->builder->getMessageCb(), ['MENU', 'Generating menus']); |
||
25 | $count = 0; |
||
26 | $this->builder->setMenus(new MenusCollection()); |
||
27 | $this->collectPages(); |
||
28 | |||
29 | /* |
||
30 | * Removing/adding/replacing menus entries from config array |
||
31 | * ie: |
||
32 | * ['site' => [ |
||
33 | * 'menu' => [ |
||
34 | * 'main' => [ |
||
35 | * 'test' => [ |
||
36 | * 'id' => 'test', |
||
37 | * 'name' => 'Test website', |
||
38 | * 'url' => 'http://test.org', |
||
39 | * 'weight' => 999, |
||
40 | * ], |
||
41 | * ], |
||
42 | * ], |
||
43 | * ]] |
||
44 | */ |
||
45 | if (!empty($this->builder->getConfig()->get('site.menu'))) { |
||
46 | foreach ($this->builder->getConfig()->get('site.menu') as $name => $entry) { |
||
47 | /* @var $menu \Cecil\Collection\Menu\Menu */ |
||
48 | $menu = $this->builder->getMenus()->get($name); |
||
49 | foreach ($entry as $property) { |
||
50 | // remove disable entries |
||
51 | if (isset($property['disabled']) && $property['disabled']) { |
||
52 | if (isset($property['id']) && $menu->has($property['id'])) { |
||
53 | $menu->remove($property['id']); |
||
54 | } |
||
55 | continue; |
||
56 | } |
||
57 | // add new entries |
||
58 | $item = (new Entry($property['id'])) |
||
59 | ->setName($property['name']) |
||
60 | ->setUrl($property['url']) |
||
61 | ->setWeight($property['weight']); |
||
62 | $menu->add($item); |
||
63 | $count++; |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 | if ($count) { |
||
68 | call_user_func_array($this->builder->getMessageCb(), ['MENU_PROGRESS', 'Start generating', 0, $count]); |
||
69 | call_user_func_array($this->builder->getMessageCb(), ['MENU_PROGRESS', 'Menus generated', $count, $count]); |
||
70 | } else { |
||
71 | call_user_func_array($this->builder->getMessageCb(), ['MENU_PROGRESS', 'No menu']); |
||
72 | } |
||
73 | } |
||
74 | |||
120 |