Conditions | 3 |
Paths | 3 |
Total Lines | 86 |
Code Lines | 39 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
150 | public function save() |
||
151 | { |
||
152 | $db = Syncable::getDatabase(); |
||
153 | $api = Syncable::getApi(); |
||
154 | |||
155 | $select = $db->prepare( |
||
156 | "SELECT * |
||
157 | FROM `events` |
||
158 | WHERE |
||
159 | `event_hash` = :event_hash AND |
||
160 | `calendar` = :calendar" |
||
161 | ); |
||
162 | $update = $db->prepare( |
||
163 | "UPDATE `events` |
||
164 | SET |
||
165 | `synced` = :synced |
||
166 | WHERE |
||
167 | `event_hash` = :event_hash AND |
||
168 | `calendar` = :calendar" |
||
169 | ); |
||
170 | $insert = $db->prepare( |
||
171 | "INSERT INTO `events` |
||
172 | ( |
||
173 | `calendar`, |
||
174 | `calendar_event[id]`, |
||
175 | `event_hash`, |
||
176 | `synced` |
||
177 | ) VALUES ( |
||
178 | :calendar, |
||
179 | :calendar_event_id, |
||
180 | :event_hash, |
||
181 | :synced |
||
182 | )" |
||
183 | ); |
||
184 | |||
185 | $params = [ |
||
186 | 'calendar' => $this->getCalendar()->getId(), |
||
187 | 'event_hash' => $this->getHash(), |
||
188 | 'synced' => Syncable::getTimestamp() |
||
189 | ]; |
||
190 | |||
191 | $select->execute($params); |
||
192 | if ($select->fetch() !== false) { |
||
193 | $update->execute($params); |
||
194 | } else { |
||
195 | /* |
||
196 | * FIXME: how sure are we of this? issue:14 |
||
197 | */ |
||
198 | /* |
||
199 | * multi-day event instance start times need to be changed to |
||
200 | * _this_ date |
||
201 | */ |
||
202 | $start = new DateTime( |
||
203 | iCalUtilityFunctions::_date2strdate( |
||
204 | $this->getProperty('DTSTART') |
||
205 | ) |
||
206 | ); |
||
207 | $end = new DateTime( |
||
208 | iCalUtilityFunctions::_date2strdate( |
||
209 | $this->getProperty('DTEND') |
||
210 | ) |
||
211 | ); |
||
212 | if ($this->getProperty('X-RECURRENCE')) { |
||
213 | $start = new DateTime($this->getProperty('X-CURRENT-DTSTART')[1]); |
||
214 | $end = new DateTime($this->getProperty('X-CURRENT-DTEND')[1]); |
||
215 | } |
||
216 | $start->setTimeZone(new DateTimeZone(self::LOCAL_TIMEZONE)); |
||
217 | $end->setTimeZone(new DateTimeZone(self::LOCAL_TIMEZONE)); |
||
218 | |||
219 | $calendarEvent = $api->post( |
||
220 | "/calendar_events", |
||
221 | [ |
||
|
|||
222 | 'calendar_event' => [ |
||
223 | 'context_code' => $this->getCalendar()->getContextCode(), |
||
224 | 'title' => $this->getProperty('SUMMARY'), |
||
225 | 'description' => $this->getProperty('DESCRIPTION', 1), |
||
226 | 'start_at' => $start->format(self::CANVAS_TIMESTAMP_FORMAT), |
||
227 | 'end_at' => $end->format(self::CANVAS_TIMESTAMP_FORMAT), |
||
228 | 'location_name' => $this->getProperty('LOCATION') |
||
229 | ] |
||
230 | ] |
||
231 | ); |
||
232 | $params['calendar_event_id'] = $calendarEvent['id']; |
||
233 | $insert->execute($params); |
||
234 | } |
||
235 | } |
||
236 | |||
336 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: