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 | abstract public function set($path = null, $value = null); | ||
| 42 | |||
| 43 | public function forceAscii() | ||
| 47 | |||
| 48 | /** | ||
| 49 | * Skip the generation of type=int. | ||
| 50 | */ | ||
| 51 | public function skipInt() | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Skip the generation of type=loc. | ||
| 58 | */ | ||
| 59 | public function skipLoc() | ||
| 63 | |||
| 64 | public function appendId($path, $id) | ||
| 68 | |||
| 69 | public function appendName($path, $name) | ||
| 79 | |||
| 80 | public function appendOrganization($path, $org) | ||
| 90 | |||
| 91 | public function appendStreet($path, $street) | ||
| 101 | |||
| 102 | public function appendCity($path, $city) | ||
| 112 | |||
| 113 | public function appendProvince($path, $sp) | ||
| 123 | |||
| 124 | public function appendPostalCode($path, $pc) | ||
| 134 | |||
| 135 | public function appendCountryCode($path, $cc) | ||
| 149 | |||
| 150 | public function appendVoice($path, $voice) | ||
| 154 | |||
| 155 | public function appendFax($path, $fax) | ||
| 159 | |||
| 160 | public function appendEmail($path, $email) | ||
| 168 | |||
| 169 | public function appendAuthInfo($path, $pw = null) | ||
| 178 | |||
| 179 | public function appendDisclose($path) | ||
| 183 | } | ||
| 184 |