| Conditions | 13 |
| Paths | 30 |
| Total Lines | 48 |
| Code Lines | 43 |
| 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 |
||
| 94 | */ |
||
| 95 | function create($type, $y = 2000, $m = 1, $d = 1, $h = 0, $i = 0, $s = 0) |
||
|
|
|||
| 96 | { |
||
| 97 | $firstDay = defined('CALENDAR_FIRST_DAY_OF_WEEK') ? CALENDAR_FIRST_DAY_OF_WEEK : 1; |
||
| 98 | switch ($type) { |
||
| 99 | case 'Day': |
||
| 100 | return new Day($y, $m, $d); |
||
| 101 | case 'Month': |
||
| 102 | // Set default state for which month type to build |
||
| 103 | if (!defined('CALENDAR_MONTH_STATE')) { |
||
| 104 | define('CALENDAR_MONTH_STATE', CALENDAR_USE_MONTH); |
||
| 105 | } |
||
| 106 | switch (CALENDAR_MONTH_STATE) { |
||
| 107 | case CALENDAR_USE_MONTH_WEEKDAYS: |
||
| 108 | $class = 'Calendar_Month_Weekdays'; |
||
| 109 | break; |
||
| 110 | case CALENDAR_USE_MONTH_WEEKS: |
||
| 111 | $class = 'Calendar_Month_Weeks'; |
||
| 112 | break; |
||
| 113 | case CALENDAR_USE_MONTH: |
||
| 114 | default: |
||
| 115 | $class = 'Pear\Calendar\Month'; |
||
| 116 | break; |
||
| 117 | } |
||
| 118 | return new $class($y, $m, $firstDay); |
||
| 119 | case 'Week': |
||
| 120 | return new Week($y, $m, $d, $firstDay); |
||
| 121 | case 'Hour': |
||
| 122 | return new Hour($y, $m, $d, $h); |
||
| 123 | case 'Minute': |
||
| 124 | return new Minute($y, $m, $d, $h, $i); |
||
| 125 | case 'Second': |
||
| 126 | return new Second($y, $m, $d, $h, $i, $s); |
||
| 127 | case 'Year': |
||
| 128 | return new Year($y); |
||
| 129 | default: |
||
| 130 | include_once 'PEAR.php'; |
||
| 131 | PEAR::raiseError('Calendar_Factory::create() unrecognised type: '.$type, |
||
| 132 | null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Factory::create()'); |
||
| 133 | return false; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Creates an instance of a calendar object, given a type and timestamp |
||
| 139 | * |
||
| 140 | * @param string $type type of object to create |
||
| 141 | * @param mixed $stamp timestamp (depending on Calendar engine being used) |
||
| 142 | * |
||
| 160 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.