| Conditions | 11 |
| Paths | 11 |
| Total Lines | 37 |
| Code Lines | 34 |
| 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 |
||
| 60 | public function getCondition($schedule, $command) |
||
| 61 | { |
||
| 62 | $condition = $command['condition']; |
||
| 63 | $at = $command['at']; |
||
| 64 | switch ($condition) { |
||
| 65 | case 'everyMinute': |
||
| 66 | $schedule->everyMinute(); |
||
| 67 | break; |
||
| 68 | case 'everyFiveMinutes': |
||
| 69 | $schedule->everyFiveMinutes(); |
||
| 70 | break; |
||
| 71 | case 'everyTenMinutes': |
||
| 72 | $schedule->everyTenMinutes(); |
||
| 73 | break; |
||
| 74 | case 'everyThirtyMinutes': |
||
| 75 | $schedule->everyThirtyMinutes(); |
||
| 76 | break; |
||
| 77 | case 'hourly': |
||
| 78 | $schedule->hourly(); |
||
| 79 | break; |
||
| 80 | case 'daily': |
||
| 81 | $schedule->daily(); |
||
| 82 | break; |
||
| 83 | case 'dailyAt': |
||
| 84 | $this->getConditionWithOption($schedule, $condition, $at); |
||
| 85 | break; |
||
| 86 | case 'weekly': |
||
| 87 | $schedule->weekly(); |
||
| 88 | break; |
||
| 89 | case 'monthly': |
||
| 90 | $schedule->monthly(); |
||
| 91 | break; |
||
| 92 | case 'yearly': |
||
| 93 | $schedule->yearly(); |
||
| 94 | break; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 119 |
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: