Conditions | 56 |
Paths | > 20000 |
Total Lines | 156 |
Code Lines | 101 |
Lines | 12 |
Ratio | 7.69 % |
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 |
||
68 | public function initValues() |
||
69 | { |
||
70 | if ($this->initDone) { |
||
71 | return; |
||
72 | } |
||
73 | |||
74 | $sessionName = self::$session_calendars . ".$this->name"; |
||
75 | $sessionValues = Session::get($sessionName); |
||
76 | if ($sessionValues) { |
||
77 | $sessionValues = unserialize($sessionValues); |
||
78 | } |
||
79 | |||
80 | // 1) View Setting |
||
81 | |||
82 | $views = array(); |
||
83 | if (isset($_REQUEST[$this->name]['view'])) { |
||
84 | $views[] = $_REQUEST[$this->name]['view']; |
||
85 | } |
||
86 | if ($this->sessionMode && $sessionValues && isset($sessionValues['view'])) { |
||
87 | $views[] = $sessionValues['view']; |
||
88 | } |
||
89 | if ($this->defaultView) { |
||
90 | $views[] = is_a($this->defaultView, 'CalendarAbstractView') ? $this->defaultView->getName() : $this->defaultView; |
||
91 | } |
||
92 | foreach ($views as $view) { |
||
93 | $view = $this->getView($view); |
||
94 | if ($view) { |
||
95 | $this->view = $view; |
||
96 | break; |
||
97 | } |
||
98 | } |
||
99 | if (! $this->view) { |
||
100 | if (count($this->views) > 0) { |
||
101 | $this->view = $this->views[0]; |
||
102 | } else { |
||
103 | return; |
||
104 | } |
||
105 | } |
||
106 | |||
107 | // 2) Year Setting |
||
108 | |||
109 | $years = array(); |
||
110 | View Code Duplication | if (isset($_REQUEST[$this->name]['year'])) { |
|
111 | $years[] = $_REQUEST[$this->name]['year']; |
||
112 | } |
||
113 | View Code Duplication | if ($this->sessionMode && $sessionValues && isset($sessionValues['year'])) { |
|
114 | $years[] = $sessionValues['year']; |
||
115 | } |
||
116 | if ($this->defaultYear) { |
||
117 | $years[] = $this->defaultYear; |
||
118 | } |
||
119 | foreach ($years as $year) { |
||
120 | if (is_numeric($year) && is_int($year + 0) && $year >= 1) { |
||
121 | $this->year = $year; |
||
122 | break; |
||
123 | } |
||
124 | } |
||
125 | if (! $this->year) { |
||
126 | $this->year = date('Y'); |
||
127 | } |
||
128 | |||
129 | // 3) Month Setting |
||
130 | |||
131 | if ($this->view->needsMonth()) { |
||
132 | $months = array(); |
||
133 | if (isset($_REQUEST[$this->name]['month'])) { |
||
134 | $months[] = $_REQUEST[$this->name]['month']; |
||
135 | } |
||
136 | if ($this->sessionMode && $sessionValues && isset($sessionValues['month'])) { |
||
137 | $months[] = $sessionValues['month']; |
||
138 | } |
||
139 | if ($this->defaultMonth) { |
||
140 | $months[] = $this->defaultMonth; |
||
141 | } |
||
142 | foreach ($months as $month) { |
||
143 | if (is_numeric($month) && is_int($month + 0)) { |
||
144 | if ($month >= 1 && $month <= 12) { |
||
145 | $this->month = $month; |
||
146 | } elseif ($month < 1) { |
||
147 | $this->year = $this->year > 1 ? $this->year - 1 : date('Y'); |
||
148 | $this->month = 12; |
||
149 | } else { |
||
150 | $this->year++; |
||
151 | $this->month = 1; |
||
152 | } |
||
153 | break; |
||
154 | } |
||
155 | } |
||
156 | if (! $this->month) { |
||
157 | $this->month = date('n'); |
||
158 | } |
||
159 | } |
||
160 | |||
161 | // 4) Day Setting |
||
162 | |||
163 | if ($this->view->needsDay()) { |
||
164 | View Code Duplication | if (isset($_REQUEST[$this->name]['day'])) { |
|
165 | $days[] = $_REQUEST[$this->name]['day']; |
||
166 | } |
||
167 | View Code Duplication | if ($this->sessionMode && $sessionValues && isset($sessionValues['day'])) { |
|
168 | $days[] = $sessionValues['day']; |
||
169 | } |
||
170 | if ($this->defaultDay) { |
||
171 | $days[] = $this->defaultDay; |
||
172 | } |
||
173 | $days[] = date('j'); |
||
174 | foreach ($days as $day) { |
||
175 | if (is_numeric($day) && is_int($day + 0)) { |
||
176 | if ($day >= 1 && $day <= 28) { |
||
177 | $this->day = $day; |
||
178 | } elseif ($day < 1) { |
||
179 | if ($this->month == 1) { |
||
180 | $this->year = $this->year > 1 ? $this->year - 1 : date('Y'); |
||
181 | $this->month = 12; |
||
182 | } else { |
||
183 | $this->month--; |
||
184 | } |
||
185 | $dayAfter = mktime(0, 0, 0, $this->month + 1, 1, $this->year); |
||
186 | $this->day = date('j', mktime(0, 0, 0, date('n', $dayAfter), date('j', $dayAfter) - 1, date('Y', $dayAfter))); |
||
187 | } else { |
||
188 | $date = mktime(0, 0, 0, $this->month, $day, $this->year); |
||
189 | if (date('n', $date) == $this->month && date('j', $date) == $day && date('Y', $date) == $this->year) { |
||
190 | $this->day = $day; |
||
191 | } else { |
||
192 | if ($this->month == 12) { |
||
193 | $this->year++; |
||
194 | $this->month = 1; |
||
195 | } else { |
||
196 | $this->month++; |
||
197 | } |
||
198 | $this->day = 1; |
||
199 | } |
||
200 | } |
||
201 | break; |
||
202 | } |
||
203 | } |
||
204 | } |
||
205 | |||
206 | $this->initDone = true; |
||
207 | |||
208 | // Session Mode |
||
209 | |||
210 | if ($this->sessionMode) { |
||
211 | list($sessionValues, $title) = $this->view->viewLinkParamsAndTitle($this); |
||
212 | $sessionValues = array_merge(array('view' => $this->view->getName()), $sessionValues); |
||
213 | $sessionValues = serialize($sessionValues); |
||
214 | Session::set($sessionName, $sessionValues); |
||
215 | } else { |
||
216 | Session::clear($sessionName); |
||
217 | } |
||
218 | |||
219 | // Css Requirements |
||
220 | Requirements::javascript(SAPPHIRE_DIR .'/thirdparty/jquery/jquery.js'); |
||
221 | Requirements::javascript('calendar/javascript/Calendar.js'); |
||
222 | Requirements::themedCSS('calendar', 'calendar'); |
||
223 | } |
||
224 | |||
401 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.