| Conditions | 1 |
| Paths | 1 |
| Total Lines | 66 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 145 | public function queries() |
||
| 146 | { |
||
| 147 | return [ |
||
| 148 | [ |
||
| 149 | 'query { |
||
| 150 | user { |
||
| 151 | ...fUser |
||
| 152 | reservations { |
||
| 153 | ...fReservation |
||
| 154 | } |
||
| 155 | } |
||
| 156 | } |
||
| 157 | fragment fReservation on ReservationInterface { |
||
| 158 | id |
||
| 159 | ... on CourtReservation { |
||
| 160 | players { |
||
| 161 | id |
||
| 162 | user { |
||
| 163 | ...fUser |
||
| 164 | } |
||
| 165 | } |
||
| 166 | } |
||
| 167 | ... on ClassReservation { |
||
| 168 | user { |
||
| 169 | ...fUser |
||
| 170 | } |
||
| 171 | } |
||
| 172 | } |
||
| 173 | fragment fUser on User { |
||
| 174 | id |
||
| 175 | fullName |
||
| 176 | }', |
||
| 177 | [ |
||
| 178 | 'data' => [ |
||
| 179 | 'user' => [ |
||
| 180 | 'id' => 'user-id-1', |
||
| 181 | 'fullName' => 'Alex', |
||
| 182 | 'reservations' => [ |
||
| 183 | [ |
||
| 184 | 'id' => 'cl-1', |
||
| 185 | 'user' => [ |
||
| 186 | 'id' => 'user-id-2', |
||
| 187 | 'fullName' => 'User class1' |
||
| 188 | ] |
||
| 189 | ], |
||
| 190 | [ |
||
| 191 | 'id' => 'court-1', |
||
| 192 | 'players' => [ |
||
| 193 | [ |
||
| 194 | 'id' => 'player-id-1', |
||
| 195 | 'user' => [ |
||
| 196 | 'id' => 'user-id-3', |
||
| 197 | 'fullName' => 'User court1' |
||
| 198 | ] |
||
| 199 | ] |
||
| 200 | ] |
||
| 201 | ], |
||
| 202 | ] |
||
| 203 | ] |
||
| 204 | ], |
||
| 205 | ], |
||
| 206 | [ |
||
| 207 | ] |
||
| 208 | ], |
||
| 209 | ]; |
||
| 210 | } |
||
| 211 | |||
| 256 | } |
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.