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