Complex classes like FlipsideAPIUser 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 FlipsideAPIUser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class FlipsideAPIUser extends User |
||
9 | { |
||
10 | private $userData; |
||
11 | private $groupData = null; |
||
12 | |||
13 | public function __construct($data = false) |
||
28 | |||
29 | public function isInGroupNamed($name) |
||
50 | |||
51 | public function __get($propName) |
||
60 | |||
61 | public function __set($propName, $value) |
||
64 | |||
65 | public function getEmail() |
||
73 | |||
74 | public function getUid() |
||
82 | |||
83 | public function getPhoneNumber() |
||
91 | |||
92 | public function getOrganization() |
||
100 | |||
101 | public function getTitles() |
||
109 | |||
110 | public function getState() |
||
118 | |||
119 | public function getCity() |
||
127 | |||
128 | public function getLastName() |
||
136 | |||
137 | public function getNickName() |
||
145 | |||
146 | public function getAddress() |
||
154 | |||
155 | public function getPostalCode() |
||
163 | |||
164 | public function getCountry() |
||
172 | |||
173 | public function getOrganizationUnits() |
||
181 | |||
182 | public function getLoginProviders() |
||
190 | } |
||
191 | |||
192 |
This check looks for the bodies of
if
statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.These
if
bodies can be removed. If you have an empty if but statements in theelse
branch, consider inverting the condition.could be turned into
This is much more concise to read.