| Conditions | 12 |
| Paths | 21 |
| Total Lines | 41 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 2 | Features | 2 |
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 |
||
| 89 | public function getNextSchedules( $fromDateStr = 'now', $limit = 5 ) |
||
| 90 | { |
||
| 91 | $dates = []; |
||
| 92 | |||
| 93 | foreach ($this->oneTimeEvents as $schedule) { |
||
| 94 | $dt = new \DateTime($fromDateStr); |
||
| 95 | $dt->modify($schedule); |
||
| 96 | |||
| 97 | if ($this->isInTimeFrame($dt, $fromDateStr)) { |
||
| 98 | $dates[] = $dt; |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | foreach ($this->schedules as $schedule) { |
||
| 103 | $d = new \DateTime($fromDateStr); |
||
| 104 | |||
| 105 | for ($i=0, $maxRecursion = 100 * $limit; $i < $limit && $maxRecursion > 0; ++$i, --$maxRecursion) { |
||
| 106 | |||
| 107 | if ($this->isDateRelative($schedule)) { |
||
| 108 | if ($this->startTime instanceof \DateTime && $d < $this->startTime->modify($d->format('Y-m-d'))) { |
||
| 109 | $d->modify($this->startTime->format('H:i:s')); |
||
| 110 | } |
||
| 111 | elseif ($this->endTime instanceof \DateTime && $d > $this->endTime->modify($d->format('Y-m-d'))) { |
||
| 112 | $d->modify('next day')->modify($this->startTime->format('H:i:s')); |
||
| 113 | } |
||
| 114 | |||
| 115 | $dates[] = clone $d; |
||
| 116 | $d->modify($schedule); |
||
| 117 | } |
||
| 118 | elseif ($this->isInTimeFrame($d->modify($schedule), $fromDateStr)) { |
||
| 119 | $dates[] = clone $d; |
||
| 120 | } |
||
| 121 | else { |
||
| 122 | --$i; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | $this->orderDates($dates); |
||
| 128 | return array_slice($dates, 0, $limit); |
||
| 129 | } |
||
| 130 | |||
| 172 | } |