| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| Code Lines | 45 |
| 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 |
||
| 82 | public function it_generates_uri_with_multiple_parents() |
||
| 83 | { |
||
| 84 | $this->page->create([ |
||
| 85 | 'is_home' => 1, |
||
| 86 | 'template' => 'default', |
||
| 87 | 'en' => [ |
||
| 88 | 'title' => 'Awesome Page', |
||
| 89 | 'slug' => 'awesome-page', |
||
| 90 | 'body' => 'My Page Body', |
||
| 91 | ], |
||
| 92 | ]); |
||
| 93 | $this->page->create([ |
||
| 94 | 'is_home' => 0, |
||
| 95 | 'template' => 'default', |
||
| 96 | 'en' => [ |
||
| 97 | 'title' => 'Mid Page', |
||
| 98 | 'slug' => 'mid-page', |
||
| 99 | 'body' => 'My Page Body', |
||
| 100 | ], |
||
| 101 | ]); |
||
| 102 | $this->page->create([ |
||
| 103 | 'is_home' => 0, |
||
| 104 | 'template' => 'default', |
||
| 105 | 'en' => [ |
||
| 106 | 'title' => 'About', |
||
| 107 | 'slug' => 'about', |
||
| 108 | 'body' => 'My Page Body', |
||
| 109 | ], |
||
| 110 | ]); |
||
| 111 | $menu = $this->createMenu('main', 'Main'); |
||
| 112 | $data = [ |
||
| 113 | 'menu_id' => $menu->id, |
||
| 114 | 'position' => 0, |
||
| 115 | 'target' => '_self', |
||
| 116 | 'page_id' => 1, |
||
| 117 | 'en' => [ |
||
| 118 | 'status' => 1, |
||
| 119 | 'title' => 'First Menu Item', |
||
| 120 | 'uri' => 'awesome-page', |
||
| 121 | ], |
||
| 122 | ]; |
||
| 123 | $this->menuItem->create($data); |
||
| 124 | $data = [ |
||
| 125 | 'menu_id' => $menu->id, |
||
| 126 | 'position' => 0, |
||
| 127 | 'target' => '_self', |
||
| 128 | 'page_id' => 2, |
||
| 129 | 'parent_id' => 1, |
||
| 130 | 'en' => [ |
||
| 131 | 'status' => 1, |
||
| 132 | 'title' => 'Second Menu Item', |
||
| 133 | 'uri' => 'awesome-page/mid-page', |
||
| 134 | ], |
||
| 135 | ]; |
||
| 136 | $this->menuItem->create($data); |
||
| 137 | |||
| 138 | self::assertEquals('awesome-page/mid-page/about', $this->menuItemUriGenerator->generateUri(3, '2', 'en')); |
||
| 139 | } |
||
| 140 | |||
| 171 |