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 |
||
14 | class SlackResourceOwner implements ResourceOwnerInterface |
||
15 | { |
||
16 | |||
17 | protected $response; |
||
18 | |||
19 | 3 | public function __construct(array $response) |
|
23 | |||
24 | /** |
||
25 | * Return all of the owner details available as an array. |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | 3 | public function toArray() |
|
33 | |||
34 | 3 | public function getId() |
|
38 | |||
39 | |||
40 | 3 | public function getName() |
|
44 | |||
45 | 3 | public function isDeleted() |
|
49 | |||
50 | 3 | public function getColor() |
|
54 | |||
55 | 3 | public function getProfile() |
|
59 | |||
60 | 3 | public function getFirstName() |
|
64 | |||
65 | 3 | public function getLastName() |
|
69 | |||
70 | 3 | public function getRealName() |
|
74 | |||
75 | 3 | public function getEmail() |
|
79 | |||
80 | 3 | public function getSkype() |
|
84 | |||
85 | 3 | public function getPhone() |
|
89 | |||
90 | 3 | public function getImage24() |
|
94 | |||
95 | 3 | public function getImage32() |
|
99 | |||
100 | 3 | public function getImage48() |
|
104 | |||
105 | 3 | public function getImage72() |
|
109 | |||
110 | 3 | public function getImage192() |
|
114 | |||
115 | 3 | public function isAdmin() |
|
119 | |||
120 | 3 | public function isOwner() |
|
124 | |||
125 | 3 | public function hasTwoFactorAuthentication() |
|
129 | |||
130 | 3 | public function hasFiles() |
|
134 | } |
||
135 |