Complex classes like ContactTrait 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. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
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 ContactTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | trait ContactTrait |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * This was once needed as the conversion done by COZA was faulty |
||
| 20 | * the bug has since been fixed but this remains to allow testing |
||
| 21 | * set true to force ascii usage on type=loc (which should allow UTF8). |
||
| 22 | * |
||
| 23 | * @var bool |
||
| 24 | */ |
||
| 25 | protected $force_ascii = false; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Set true to skip the generation of type=int. |
||
| 29 | * |
||
| 30 | * @var bool |
||
| 31 | */ |
||
| 32 | protected $skip_int = false; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Set true to skip the generation of type=loc. |
||
| 36 | * |
||
| 37 | * @var bool |
||
| 38 | */ |
||
| 39 | protected $skip_loc = false; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param string $path |
||
| 43 | * @param mixed $value |
||
| 44 | * |
||
| 45 | * @return \DOMElement |
||
| 46 | */ |
||
| 47 | abstract public function set($path = null, $value = null); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Whether to force ASCI on loc contacts |
||
| 51 | * |
||
| 52 | * @param bool $value |
||
| 53 | * |
||
| 54 | * @see \AfriCC\EPP\ContactTrait::force_ascii |
||
| 55 | */ |
||
| 56 | public function forceAscii($value = true) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Skip the generation of type=int. |
||
| 63 | * |
||
| 64 | * @param bool $value |
||
| 65 | */ |
||
| 66 | public function skipInt($value = true) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Skip the generation of type=loc. |
||
| 73 | * |
||
| 74 | * @param bool $value |
||
| 75 | */ |
||
| 76 | public function skipLoc($value = true) |
||
| 80 | |||
| 81 | public function appendId($path, $id) |
||
| 85 | |||
| 86 | public function appendName($path, $name) |
||
| 96 | |||
| 97 | public function appendOrganization($path, $org) |
||
| 107 | |||
| 108 | public function appendStreet($path, $street) |
||
| 118 | |||
| 119 | public function appendCity($path, $city) |
||
| 129 | |||
| 130 | public function appendProvince($path, $sp) |
||
| 140 | |||
| 141 | public function appendPostalCode($path, $pc) |
||
| 151 | |||
| 152 | public function appendCountryCode($path, $cc) |
||
| 166 | |||
| 167 | public function appendVoice($path, $voice, $extension = null) |
||
| 175 | |||
| 176 | public function appendFax($path, $fax, $extension = null) |
||
| 184 | |||
| 185 | public function appendEmail($path, $email) |
||
| 193 | |||
| 194 | public function appendAuthInfo($path, $pw = null) |
||
| 203 | |||
| 204 | public function appendDisclose($path) |
||
| 208 | } |
||
| 209 |