Conditions | 28 |
Paths | 687 |
Total Lines | 83 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Tests | 21 |
CRAP Score | 254.7314 |
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 |
||
134 | 2 | public static function serializeProperty(\Sabre\VObject\Property $property) { |
|
135 | 2 | if(!in_array($property->name, Properties::$indexProperties)) { |
|
136 | 2 | return; |
|
137 | } |
||
138 | 2 | $value = $property->getValue(); |
|
|
|||
139 | 2 | if($property->name == 'ADR' || $property->name == 'N' || $property->name == 'ORG' || $property->name == 'CATEGORIES') { |
|
140 | 2 | $value = $property->getParts(); |
|
141 | 2 | $value = array_map('trim', $value); |
|
142 | 2 | } |
|
143 | 2 | elseif($property->name == 'BDAY') { |
|
144 | // If the BDAY has a format of e.g. 19960401 |
||
145 | if(strlen($value) >= 8 |
||
146 | && is_int(substr($value, 0, 4)) |
||
147 | && is_int(substr($value, 4, 2)) |
||
148 | && is_int(substr($value, 6, 2))) { |
||
149 | $value = substr($value, 0, 4).'-'.substr($value, 4, 2).'-'.substr($value, 6, 2); |
||
150 | } else if($value[5] !== '-' || $value[7] !== '-') { |
||
151 | try { |
||
152 | // Skype exports as e.g. Jan 14, 1996 |
||
153 | $date = new \DateTime($value); |
||
154 | $value = $date->format('Y-m-d'); |
||
155 | } catch(\Exception $e) { |
||
156 | \OCP\Util::writeLog('contacts', __METHOD__.' Error parsing date: ' . $value, \OCP\Util::DEBUG); |
||
157 | return; |
||
158 | } |
||
159 | } |
||
160 | // Otherwise we assume it's OK. |
||
161 | 2 | } elseif($property->name == 'PHOTO') { |
|
162 | $value = true; |
||
163 | } |
||
164 | 2 | elseif($property->name == 'IMPP') { |
|
165 | if(strpos($value, ':') !== false) { |
||
166 | $value = explode(':', $value); |
||
167 | $protocol = array_shift($value); |
||
168 | if(!isset($property['X-SERVICE-TYPE'])) { |
||
169 | $property['X-SERVICE-TYPE'] = strtoupper($protocol); |
||
170 | } |
||
171 | $value = implode('', $value); |
||
172 | } |
||
173 | } |
||
174 | 2 | if(is_string($value)) { |
|
175 | 2 | $value = strtr($value, array('\,' => ',', '\;' => ';')); |
|
176 | 2 | } |
|
177 | $temp = array( |
||
178 | //'name' => $property->name, |
||
179 | 2 | 'value' => $value, |
|
180 | 2 | 'parameters' => array() |
|
181 | 2 | ); |
|
182 | |||
183 | // This cuts around a 3rd off of the json response size. |
||
184 | 2 | if(in_array($property->name, Properties::$multiProperties)) { |
|
185 | $temp['checksum'] = substr(md5($property->serialize()), 0, 8); |
||
186 | } |
||
187 | 2 | foreach($property->parameters as $parameter) { |
|
188 | // Faulty entries by kaddressbook |
||
189 | // Actually TYPE=PREF is correct according to RFC 2426 |
||
190 | // but this way is more handy in the UI. Tanghus. |
||
191 | if($parameter->name == 'TYPE' && strtoupper($parameter->getValue()) == 'PREF') { |
||
192 | $parameter->name = 'PREF'; |
||
193 | $parameter->setValue('1'); |
||
194 | } |
||
195 | // NOTE: Apparently \Sabre\VObject\Reader can't always deal with value list parameters |
||
196 | // like TYPE=HOME,CELL,VOICE. Tanghus. |
||
197 | // TODO: Check if parameter is has commas and split + merge if so. |
||
198 | if ($parameter->name == 'TYPE') { |
||
199 | $pvalue = $parameter->getValue(); |
||
200 | if(is_string($pvalue) && strpos($pvalue, ',') !== false) { |
||
201 | $pvalue = array_map('trim', explode(',', $pvalue)); |
||
202 | } |
||
203 | $pvalue = is_array($pvalue) ? $pvalue : array($pvalue); |
||
204 | if (isset($temp['parameters'][$parameter->name])) { |
||
205 | $temp['parameters'][$parameter->name][] = \OCP\Util::sanitizeHTML($pvalue); |
||
206 | } |
||
207 | else { |
||
208 | $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($pvalue); |
||
209 | } |
||
210 | } |
||
211 | else{ |
||
212 | $temp['parameters'][$parameter->name] = \OCP\Util::sanitizeHTML($parameter->getValue()); |
||
213 | } |
||
214 | 2 | } |
|
215 | 2 | return $temp; |
|
216 | } |
||
217 | } |
||
218 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.