| Total Complexity | 40 |
| Total Lines | 363 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like vCard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use vCard, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 91 | class vCard |
||
| 92 | { |
||
| 93 | /** |
||
| 94 | * @var array array of properties |
||
| 95 | */ |
||
| 96 | public $properties; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @var string filename |
||
| 100 | */ |
||
| 101 | public $filename; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @var string encoding |
||
| 105 | */ |
||
| 106 | public $encoding = "ISO-8859-1;ENCODING=QUOTED-PRINTABLE"; |
||
| 107 | |||
| 108 | |||
| 109 | /** |
||
| 110 | * mise en forme du numero de telephone |
||
| 111 | * |
||
| 112 | * @param int $number numero de telephone |
||
| 113 | * @param string $type Type |
||
| 114 | * @return void |
||
| 115 | */ |
||
| 116 | public function setPhoneNumber($number, $type = "") |
||
| 117 | { |
||
| 118 | // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE" |
||
| 119 | $key = "TEL"; |
||
| 120 | if ($type != "") { |
||
| 121 | $key .= ";".$type; |
||
| 122 | } |
||
| 123 | $key .= ";CHARSET=".$this->encoding; |
||
| 124 | $this->properties[$key] = encode($number); |
||
| 125 | } |
||
| 126 | |||
| 127 | /** |
||
| 128 | * mise en forme de la photo |
||
| 129 | * warning NON TESTE ! |
||
| 130 | * |
||
| 131 | * @param string $type Type |
||
| 132 | * @param string $photo Photo |
||
| 133 | * @return void |
||
| 134 | */ |
||
| 135 | public function setPhoto($type, $photo) |
||
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * mise en forme du nom formate |
||
| 143 | * |
||
| 144 | * @param string $name Name |
||
| 145 | * @return void |
||
| 146 | */ |
||
| 147 | public function setFormattedName($name) |
||
| 148 | { |
||
| 149 | $this->properties["FN;CHARSET=".$this->encoding] = encode($name); |
||
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * mise en forme du nom complet |
||
| 154 | * |
||
| 155 | * @param string $family Family name |
||
| 156 | * @param string $first First name |
||
| 157 | * @param string $additional Additional (e.g. second name, nick name) |
||
| 158 | * @param string $prefix Prefix (e.g. "Mr.", "Ms.", "Prof.") |
||
| 159 | * @param string $suffix Suffix (e.g. "sen." for senior, "jun." for junior) |
||
| 160 | * @return void |
||
| 161 | */ |
||
| 162 | public function setName($family = "", $first = "", $additional = "", $prefix = "", $suffix = "") |
||
| 163 | { |
||
| 164 | $this->properties["N;CHARSET=".$this->encoding] = encode($family).";".encode($first).";".encode($additional).";".encode($prefix).";".encode($suffix); |
||
| 165 | $this->filename = "$first%20$family.vcf"; |
||
| 166 | if (empty($this->properties["FN"])) { |
||
| 167 | $this->setFormattedName(trim("$prefix $first $additional $family $suffix")); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * mise en forme de l'anniversaire |
||
| 173 | * |
||
| 174 | * @param integer $date Date |
||
| 175 | * @return void |
||
| 176 | */ |
||
| 177 | public function setBirthday($date) |
||
| 178 | { |
||
| 179 | // $date format is YYYY-MM-DD - RFC 2425 and RFC 2426 |
||
| 180 | $this->properties["BDAY"] = dol_print_date($date, 'dayrfc'); |
||
| 181 | } |
||
| 182 | |||
| 183 | /** |
||
| 184 | * mise en forme de l'adresse |
||
| 185 | * |
||
| 186 | * @param string $postoffice Postoffice |
||
| 187 | * @param string $extended Extended |
||
| 188 | * @param string $street Street |
||
| 189 | * @param string $city City |
||
| 190 | * @param string $region Region |
||
| 191 | * @param string $zip Zip |
||
| 192 | * @param string $country Country |
||
| 193 | * @param string $type Type |
||
| 194 | * @return void |
||
| 195 | */ |
||
| 196 | public function setAddress($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL") |
||
| 197 | { |
||
| 198 | // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL" |
||
| 199 | $key = "ADR"; |
||
| 200 | if ($type != "") { |
||
| 201 | $key .= ";".$type; |
||
| 202 | } |
||
| 203 | $key .= ";CHARSET=".$this->encoding; |
||
| 204 | $this->properties[$key] = ";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country); |
||
| 205 | |||
| 206 | //if ($this->properties["LABEL;".$type.";CHARSET=".$this->encoding] == '') { |
||
| 207 | //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type); |
||
| 208 | //} |
||
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * mise en forme du label |
||
| 213 | * |
||
| 214 | * @param string $postoffice Postoffice |
||
| 215 | * @param string $extended Extended |
||
| 216 | * @param string $street Street |
||
| 217 | * @param string $city City |
||
| 218 | * @param string $region Region |
||
| 219 | * @param string $zip Zip |
||
| 220 | * @param string $country Country |
||
| 221 | * @param string $type Type |
||
| 222 | * @return void |
||
| 223 | */ |
||
| 224 | public function setLabel($postoffice = "", $extended = "", $street = "", $city = "", $region = "", $zip = "", $country = "", $type = "HOME;POSTAL") |
||
| 225 | { |
||
| 226 | $label = ""; |
||
| 227 | if ($postoffice != "") { |
||
| 228 | $label .= "$postoffice\r\n"; |
||
| 229 | } |
||
| 230 | if ($extended != "") { |
||
| 231 | $label .= "$extended\r\n"; |
||
| 232 | } |
||
| 233 | if ($street != "") { |
||
| 234 | $label .= "$street\r\n"; |
||
| 235 | } |
||
| 236 | if ($zip != "") { |
||
| 237 | $label .= "$zip "; |
||
| 238 | } |
||
| 239 | if ($city != "") { |
||
| 240 | $label .= "$city\r\n"; |
||
| 241 | } |
||
| 242 | if ($region != "") { |
||
| 243 | $label .= "$region\r\n"; |
||
| 244 | } |
||
| 245 | if ($country != "") { |
||
| 246 | $country .= "$country\r\n"; |
||
| 247 | } |
||
| 248 | |||
| 249 | $this->properties["LABEL;$type;CHARSET=".$this->encoding] = encode($label); |
||
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Add a e-mail address to this vCard |
||
| 254 | * |
||
| 255 | * @param string $address E-mail address |
||
| 256 | * @param string $type (optional) The type of the e-mail (typical "PREF;INTERNET" or "INTERNET") |
||
| 257 | * @return void |
||
| 258 | */ |
||
| 259 | public function setEmail($address, $type = "TYPE=INTERNET;PREF") |
||
| 260 | { |
||
| 261 | $key = "EMAIL"; |
||
| 262 | if ($type != "") { |
||
| 263 | $key .= ";".$type; |
||
| 264 | } |
||
| 265 | $this->properties[$key] = $address; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * mise en forme de la note |
||
| 270 | * |
||
| 271 | * @param string $note Note |
||
| 272 | * @return void |
||
| 273 | */ |
||
| 274 | public function setNote($note) |
||
| 275 | { |
||
| 276 | $this->properties["NOTE;CHARSET=".$this->encoding] = encode($note); |
||
| 277 | } |
||
| 278 | |||
| 279 | /** |
||
| 280 | * mise en forme de la fonction |
||
| 281 | * |
||
| 282 | * @param string $title Title |
||
| 283 | * @return void |
||
| 284 | */ |
||
| 285 | public function setTitle($title) |
||
| 286 | { |
||
| 287 | $this->properties["TITLE;CHARSET=".$this->encoding] = encode($title); |
||
| 288 | } |
||
| 289 | |||
| 290 | |||
| 291 | /** |
||
| 292 | * mise en forme de la societe |
||
| 293 | * |
||
| 294 | * @param string $org Org |
||
| 295 | * @return void |
||
| 296 | */ |
||
| 297 | public function setOrg($org) |
||
| 298 | { |
||
| 299 | $this->properties["ORG;CHARSET=".$this->encoding] = encode($org); |
||
| 300 | } |
||
| 301 | |||
| 302 | |||
| 303 | /** |
||
| 304 | * mise en forme du logiciel generateur |
||
| 305 | * |
||
| 306 | * @param string $prodid Prodid |
||
| 307 | * @return void |
||
| 308 | */ |
||
| 309 | public function setProdId($prodid) |
||
| 310 | { |
||
| 311 | $this->properties["PRODID;CHARSET=".$this->encoding] = encode($prodid); |
||
| 312 | } |
||
| 313 | |||
| 314 | |||
| 315 | /** |
||
| 316 | * mise en forme du logiciel generateur |
||
| 317 | * |
||
| 318 | * @param string $uid Uid |
||
| 319 | * @return void |
||
| 320 | */ |
||
| 321 | public function setUID($uid) |
||
| 322 | { |
||
| 323 | $this->properties["UID;CHARSET=".$this->encoding] = encode($uid); |
||
| 324 | } |
||
| 325 | |||
| 326 | |||
| 327 | /** |
||
| 328 | * mise en forme de l'url |
||
| 329 | * |
||
| 330 | * @param string $url URL |
||
| 331 | * @param string $type Type |
||
| 332 | * @return void |
||
| 333 | */ |
||
| 334 | public function setURL($url, $type = "") |
||
| 342 | } |
||
| 343 | |||
| 344 | /** |
||
| 345 | * permet d'obtenir une vcard |
||
| 346 | * |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | public function getVCard() |
||
| 350 | { |
||
| 351 | $text = "BEGIN:VCARD\r\n"; |
||
| 352 | $text .= "VERSION:3.0\r\n"; |
||
| 353 | //$text.= "VERSION:2.1\r\n"; |
||
| 354 | foreach ($this->properties as $key => $value) { |
||
| 355 | $text .= "$key:$value\r\n"; |
||
| 356 | } |
||
| 357 | $text .= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n"; |
||
| 358 | $text .= "MAILER: Dolibarr\r\n"; |
||
| 359 | $text .= "END:VCARD\r\n"; |
||
| 360 | return $text; |
||
| 361 | } |
||
| 362 | |||
| 363 | /** |
||
| 364 | * permet d'obtenir le nom de fichier |
||
| 365 | * |
||
| 366 | * @return string Filename |
||
| 367 | */ |
||
| 368 | public function getFileName() |
||
| 369 | { |
||
| 370 | return $this->filename; |
||
| 371 | } |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Return a VCARD string |
||
| 375 | * |
||
| 376 | * @param Object $object Object |
||
| 377 | * @param Societe $company Company |
||
| 378 | * @param Translate $langs Lang object |
||
| 379 | * @return string String |
||
| 380 | */ |
||
| 381 | public function buildVCardString($object, $company, $langs) |
||
| 454 | } |
||
| 455 | |||
| 456 | |||
| 457 | /* Example from Microsoft Outlook 2019 |
||
| 458 | |||
| 459 | BEGIN:VCARD |
||
| 460 | VERSION:2.1 |
||
| 461 | |||
| 462 | N;LANGUAGE=de:surename;forename;secondname;Sir;jun. |
||
| 463 | FN:Sir surename secondname forename jun. |
||
| 464 | ORG:Companyname |
||
| 465 | TITLE:position |
||
| 466 | TEL;WORK;VOICE:work-phone-number |
||
| 467 | TEL;HOME;VOICE:private-phone-number |
||
| 468 | TEL;CELL;VOICE:mobile-phone-number |
||
| 485 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths