| Conditions | 1 |
| Paths | 1 |
| Total Lines | 73 |
| Code Lines | 49 |
| 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 |
||
| 116 | public function testDashboardGroups() |
||
| 117 | { |
||
| 118 | $config = $this->process([[ |
||
| 119 | 'dashboard' => [ |
||
| 120 | 'groups' => [ |
||
| 121 | 'bar' => [ |
||
| 122 | 'label' => 'foo', |
||
| 123 | 'icon' => '<i class="fa fa-edit"></i>', |
||
| 124 | 'items' => [ |
||
| 125 | 'item1', |
||
| 126 | 'item2', |
||
| 127 | [ |
||
| 128 | 'label' => 'fooLabel', |
||
| 129 | 'route' => 'fooRoute', |
||
| 130 | 'route_params' => ['bar' => 'foo'], |
||
| 131 | 'route_absolute' => true, |
||
| 132 | ], |
||
| 133 | [ |
||
| 134 | 'label' => 'barLabel', |
||
| 135 | 'route' => 'barRoute', |
||
| 136 | ], |
||
| 137 | ], |
||
| 138 | ], |
||
| 139 | ], |
||
| 140 | ], |
||
| 141 | ]]); |
||
| 142 | |||
| 143 | $this->assertCount(4, $config['dashboard']['groups']['bar']['items']); |
||
| 144 | $this->assertSame( |
||
| 145 | $config['dashboard']['groups']['bar']['items'][0], |
||
| 146 | [ |
||
| 147 | 'admin' => 'item1', |
||
| 148 | 'label' => '', |
||
| 149 | 'route' => '', |
||
| 150 | 'route_params' => [], |
||
| 151 | 'route_absolute' => false, |
||
| 152 | 'roles' => [], |
||
| 153 | ] |
||
| 154 | ); |
||
| 155 | $this->assertSame( |
||
| 156 | $config['dashboard']['groups']['bar']['items'][1], |
||
| 157 | [ |
||
| 158 | 'admin' => 'item2', |
||
| 159 | 'label' => '', |
||
| 160 | 'route' => '', |
||
| 161 | 'route_params' => [], |
||
| 162 | 'route_absolute' => false, |
||
| 163 | 'roles' => [], |
||
| 164 | ] |
||
| 165 | ); |
||
| 166 | $this->assertSame( |
||
| 167 | $config['dashboard']['groups']['bar']['items'][2], |
||
| 168 | [ |
||
| 169 | 'label' => 'fooLabel', |
||
| 170 | 'route' => 'fooRoute', |
||
| 171 | 'route_params' => ['bar' => 'foo'], |
||
| 172 | 'route_absolute' => true, |
||
| 173 | 'admin' => '', |
||
| 174 | 'roles' => [], |
||
| 175 | ] |
||
| 176 | ); |
||
| 177 | $this->assertSame( |
||
| 178 | $config['dashboard']['groups']['bar']['items'][3], |
||
| 179 | [ |
||
| 180 | 'label' => 'barLabel', |
||
| 181 | 'route' => 'barRoute', |
||
| 182 | 'route_params' => [], |
||
| 183 | 'admin' => '', |
||
| 184 | 'roles' => [], |
||
| 185 | 'route_absolute' => false, |
||
| 186 | ] |
||
| 187 | ); |
||
| 188 | } |
||
| 189 | |||
| 235 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.