| Conditions | 11 |
| Paths | 65 |
| Total Lines | 51 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 30 | public function __construct($start, $interval = null, $end = null, $options = null) |
||
| 31 | { |
||
| 32 | // deal with ISO string calls first |
||
| 33 | if (func_num_args() < 3 and is_string($start)) |
||
| 34 | { |
||
| 35 | parent::__construct($start, $interval); |
||
| 36 | return; |
||
| 37 | } |
||
| 38 | |||
| 39 | // make sure $start is a DateTime object |
||
| 40 | if ( ! $start instanceOf DateTime) |
||
| 41 | { |
||
| 42 | // use Date instead of DateTime, it is more flexible |
||
| 43 | $start = new Date($start); |
||
| 44 | } |
||
| 45 | |||
| 46 | // we need a DateTime object to continue |
||
| 47 | if ($start instanceOf Date) |
||
| 48 | { |
||
| 49 | $start = $start->getDateTime(); |
||
| 50 | } |
||
| 51 | |||
| 52 | // make sure $interval is a DateInterval object |
||
| 53 | if ( ! $interval instanceOf DateInterval) |
||
| 54 | { |
||
| 55 | $interval = DateInterval::createFromDateString($interval); |
||
| 56 | } |
||
| 57 | |||
| 58 | // make sure $end is a DateTime object |
||
| 59 | if ( ! $end instanceOf DateTime) |
||
| 60 | { |
||
| 61 | // recurrences limited to 10000, any larger and we assume its a timestamp |
||
| 62 | if (is_numeric($end) and $end > 10000) |
||
| 63 | { |
||
| 64 | // use Date instead of DateTime, it is more flexible |
||
| 65 | $end = new Date('@'.$end); |
||
| 66 | } |
||
| 67 | elseif (is_string($end)) |
||
| 68 | { |
||
| 69 | $end = new Date($end); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | // we need a DateTime object to continue |
||
| 74 | if ($end instanceOf Date) |
||
| 75 | { |
||
| 76 | $end = $end->getDateTime(); |
||
| 77 | } |
||
| 78 | |||
| 79 | parent::__construct($start, $interval, $end, $options); |
||
| 80 | } |
||
| 81 | /** |
||
| 129 |