Complex classes like SlackResourceOwner 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 SlackResourceOwner, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
13 | class SlackResourceOwner implements ResourceOwnerInterface |
||
14 | { |
||
15 | |||
16 | protected $response; |
||
17 | |||
18 | public function __construct(array $response) |
||
22 | |||
23 | /** |
||
24 | * Return all of the owner details available as an array. |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | public function toArray() |
||
32 | |||
33 | public function getId() |
||
37 | |||
38 | |||
39 | public function getName() |
||
43 | |||
44 | public function isDeleted() |
||
48 | |||
49 | public function getColor() |
||
53 | |||
54 | public function getProfile() |
||
58 | |||
59 | public function getFirstName() |
||
63 | |||
64 | public function getLastName() |
||
68 | |||
69 | public function getRealName() |
||
73 | |||
74 | public function getEmail() |
||
78 | |||
79 | public function getSkype() |
||
83 | |||
84 | public function getPhone() |
||
88 | |||
89 | public function getImage24() |
||
93 | |||
94 | public function getImage32() |
||
98 | |||
99 | public function getImage48() |
||
103 | |||
104 | public function getImage72() |
||
108 | |||
109 | public function getImage192() |
||
113 | |||
114 | public function isAdmin() |
||
118 | |||
119 | public function isOwner() |
||
123 | |||
124 | public function hasTwoFactorAuthentication() |
||
128 | |||
129 | public function hasFiles() |
||
133 | } |
||
134 |