| Conditions | 11 |
| Paths | 9 |
| Total Lines | 37 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 69 | public static function getExecutionDate(Recurrence $recurrence) |
||
| 70 | { |
||
| 71 | $formatter = Yii::$app->formatter; |
||
| 72 | switch ($recurrence->frequency) { |
||
| 73 | case RecurrenceFrequency::DAY: |
||
| 74 | $date = strtotime("+1 day", strtotime($recurrence->started_at)); |
||
| 75 | break; |
||
| 76 | case RecurrenceFrequency::WEEK: |
||
| 77 | $currentWeekDay = $formatter->asDatetime('now', 'php:N') - 1; |
||
| 78 | $weekDay = $recurrence->schedule; |
||
| 79 | $addDay = $currentWeekDay > $weekDay ? 7 - $currentWeekDay + $weekDay : $weekDay - $currentWeekDay; |
||
| 80 | $date = strtotime("+{$addDay} day", strtotime($recurrence->started_at)); |
||
| 81 | break; |
||
| 82 | |||
| 83 | case RecurrenceFrequency::MONTH: |
||
| 84 | $currDay = $formatter->asDatetime('now', 'php:d'); |
||
| 85 | $d = $recurrence->schedule; |
||
| 86 | $date = Yii::$app->formatter->asDatetime($currDay > $d ? strtotime('+1 month') : time(), 'php:Y-m'); |
||
| 87 | $d = sprintf("%02d", $d); |
||
| 88 | return "{$date}-{$d}"; |
||
| 89 | case RecurrenceFrequency::YEAR: |
||
| 90 | $m = current(explode('-', $recurrence->schedule)); |
||
| 91 | $currMonth = $formatter->asDatetime('now', 'php:m'); |
||
| 92 | $y = Yii::$app->formatter->asDatetime($currMonth > $m ? strtotime('+1 year') : time(), 'php:Y'); |
||
| 93 | return "{$y}-{$recurrence->schedule}"; |
||
| 94 | case RecurrenceFrequency::WORKING_DAY: |
||
| 95 | if (($currentWeekDay = $formatter->asDatetime('now', 'php:N') - 1) > 5) { |
||
| 96 | return null; |
||
| 97 | } |
||
| 98 | $date = strtotime("+1 day", strtotime($recurrence->started_at)); |
||
| 99 | break; |
||
| 100 | case RecurrenceFrequency::LEGAL_WORKING_DAY: |
||
| 101 | return HolidayHelper::getNextWorkday(); |
||
| 102 | default: |
||
| 103 | return null; |
||
| 104 | } |
||
| 105 | return $formatter->asDatetime($date, 'php:Y-m-d'); |
||
| 106 | } |
||
| 159 |