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 | case CALENDAR_USE_MONTH_WEEKDAYS: |
||
95 | $class = 'Calendar_Month_Weekdays'; |
||
96 | break; |
||
97 | case CALENDAR_USE_MONTH_WEEKS: |
||
98 | $class = 'Calendar_Month_Weeks'; |
||
99 | break; |
||
100 | case CALENDAR_USE_MONTH: |
||
101 | default: |
||
102 | $class = 'Pear\Calendar\Month'; |
||
103 | break; |
||
104 | } |
||
105 | return new $class($y, $m, $firstDay); |
||
106 | case 'Week': |
||
107 | return new Week($y, $m, $d, $firstDay); |
||
108 | case 'Hour': |
||
109 | return new Hour($y, $m, $d, $h); |
||
110 | case 'Minute': |
||
111 | return new Minute($y, $m, $d, $h, $i); |
||
112 | case 'Second': |
||
113 | return new Second($y, $m, $d, $h, $i, $s); |
||
114 | case 'Year': |
||
115 | return new Year($y); |
||
116 | default: |
||
117 | include_once 'PEAR.php'; |
||
118 | PEAR::raiseError('Calendar_Factory::create() unrecognised type: '.$type, |
||
119 | null, PEAR_ERROR_TRIGGER, E_USER_NOTICE, 'Calendar_Factory::create()'); |
||
120 | return false; |
||
121 | } |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Creates an instance of a calendar object, given a type and timestamp |
||
126 | * |
||
127 | * @param string $type type of object to create |
||
128 | * @param mixed $stamp timestamp (depending on Calendar engine being used) |
||
129 | * |
||
130 | * @return object subclass of Calendar |
||
131 | * @access public |
||
132 | * @static |
||
133 | */ |
||
134 | function & createByTimestamp($type, $stamp) |
||
135 | { |
||
136 | $cE = & Calendar_Engine_Factory::getEngine(); |
||
137 | $y = $cE->stampToYear($stamp); |
||
138 | $m = $cE->stampToMonth($stamp); |
||
139 | $d = $cE->stampToDay($stamp); |
||
140 | $h = $cE->stampToHour($stamp); |
||
141 | $i = $cE->stampToMinute($stamp); |
||
142 | $s = $cE->stampToSecond($stamp); |
||
147 |
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.