| Conditions | 3 |
| Paths | 3 |
| Total Lines | 100 |
| Code Lines | 46 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 122 | public function save() |
||
| 123 | { |
||
| 124 | $db = static::getDatabase(); |
||
| 125 | $api = static::getApi(); |
||
| 126 | |||
| 127 | $select = $db->prepare( |
||
| 128 | "SELECT * |
||
| 129 | FROM `events` |
||
| 130 | WHERE |
||
| 131 | `event_hash` = :event_hash AND |
||
| 132 | `calendar` = :calendar" |
||
| 133 | ); |
||
| 134 | $update = $db->prepare( |
||
| 135 | "UPDATE `events` |
||
| 136 | SET |
||
| 137 | `synced` = :synced |
||
| 138 | WHERE |
||
| 139 | `event_hash` = :event_hash AND |
||
| 140 | `calendar` = :calendar" |
||
| 141 | ); |
||
| 142 | $insert = $db->prepare( |
||
| 143 | "INSERT INTO `events` |
||
| 144 | ( |
||
| 145 | `calendar`, |
||
| 146 | `calendar_event[id]`, |
||
| 147 | `event_hash`, |
||
| 148 | `synced` |
||
| 149 | ) VALUES ( |
||
| 150 | :calendar, |
||
| 151 | :calendar_event_id, |
||
| 152 | :event_hash, |
||
| 153 | :synced |
||
| 154 | )" |
||
| 155 | ); |
||
| 156 | |||
| 157 | $params = [ |
||
| 158 | 'calendar' => $this->getCalendar()->getId(), |
||
| 159 | 'event_hash' => $this->getHash(), |
||
| 160 | 'synced' => Syncable::getTimestamp() |
||
| 161 | ]; |
||
| 162 | |||
| 163 | $select->execute($params); |
||
| 164 | if ($select->fetch() !== false) { |
||
| 165 | $update->execute($params); |
||
| 166 | } else { |
||
| 167 | /* |
||
| 168 | * FIXME: how sure are we of this? issue:14 |
||
| 169 | */ |
||
| 170 | /* |
||
| 171 | * multi-day event instance start times need to be changed to |
||
| 172 | * _this_ date |
||
| 173 | */ |
||
| 174 | $start = new DateTime( |
||
| 175 | iCalUtilityFunctions::_date2strdate( |
||
| 176 | $this->getProperty('DTSTART') |
||
| 177 | ) |
||
| 178 | ); |
||
| 179 | $end = new DateTime( |
||
| 180 | iCalUtilityFunctions::_date2strdate( |
||
| 181 | $this->getProperty('DTEND') |
||
| 182 | ) |
||
| 183 | ); |
||
| 184 | if ($this->getProperty('X-RECURRENCE')) { |
||
| 185 | $start = new DateTime($this->getProperty('X-CURRENT-DTSTART')[1]); |
||
| 186 | $end = new DateTime($this->getProperty('X-CURRENT-DTEND')[1]); |
||
| 187 | } |
||
| 188 | $start->setTimeZone(new DateTimeZone(self::LOCAL_TIMEZONE)); |
||
| 189 | $end->setTimeZone(new DateTimeZone(self::LOCAL_TIMEZONE)); |
||
| 190 | |||
| 191 | $calendarEvent = $api->post( |
||
| 192 | "/calendar_events", |
||
| 193 | [ |
||
| 194 | 'calendar_event' => [ |
||
| 195 | 'context_code' => $this->getCalendar()->getContextCode(), |
||
| 196 | /* |
||
| 197 | * TODO this should be configurable issue:5 |
||
| 198 | */ |
||
| 199 | /* removing trailing [TAGS] from event title */ |
||
| 200 | 'title' => preg_replace( |
||
| 201 | '%^([^\]]+)(\s*\[[^\]]+\]\s*)+$%', |
||
| 202 | '\\1', |
||
| 203 | strip_tags($this->getProperty('SUMMARY')) |
||
| 204 | ), |
||
| 205 | 'description' => Markdown::defaultTransform( |
||
| 206 | str_replace( |
||
| 207 | '\n', |
||
| 208 | "\n\n", |
||
| 209 | $this->getProperty('DESCRIPTION', 1) |
||
| 210 | ) |
||
| 211 | ), |
||
| 212 | 'start_at' => $start->format(self::CANVAS_TIMESTAMP_FORMAT), |
||
| 213 | 'end_at' => $end->format(self::CANVAS_TIMESTAMP_FORMAT), |
||
| 214 | 'location_name' => $this->getProperty('LOCATION') |
||
| 215 | ] |
||
| 216 | ] |
||
| 217 | ); |
||
| 218 | $params['calendar_event_id'] = $calendarEvent['id']; |
||
| 219 | $insert->execute($params); |
||
| 220 | } |
||
| 221 | } |
||
| 222 | |||
| 303 |
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: