Complex classes like Project 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 Project, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | class Project |
||
16 | { |
||
17 | /** |
||
18 | * The name of the project |
||
19 | * @var string |
||
20 | */ |
||
21 | private $name; |
||
22 | |||
23 | /** |
||
24 | * The account the project is associated with |
||
25 | * @var integer |
||
26 | */ |
||
27 | private $accountId; |
||
28 | |||
29 | /** |
||
30 | * The significance level at which you would like to declare winning and |
||
31 | * losing variations. A lower number minimizes the time needed to declare a |
||
32 | * winning or losing variation, but increases the risk that your results |
||
33 | * aren't true winners and losers. The precision for this number is up to 4 |
||
34 | * decimal places. |
||
35 | * |
||
36 | * @var number |
||
37 | */ |
||
38 | private $confidenceThreshold; |
||
39 | |||
40 | /** |
||
41 | * The ID of a Dynamic Customer Profile Service associated with this project. |
||
42 | * @var integer |
||
43 | */ |
||
44 | private $dcpServiceId; |
||
45 | |||
46 | /** |
||
47 | * The platform of the project. Can be 'web', 'ios', 'android' or 'custom'. |
||
48 | * @var string |
||
49 | */ |
||
50 | private $platform; |
||
51 | |||
52 | /** |
||
53 | * The language to generate example code in. |
||
54 | * @var array[string] |
||
55 | */ |
||
56 | private $sdks; |
||
57 | |||
58 | /** |
||
59 | * The current status of the project. Can be 'active' or 'archived'. |
||
60 | * @var string |
||
61 | */ |
||
62 | private $status; |
||
63 | |||
64 | /** |
||
65 | * Web snippet-specific configuration for this project. |
||
66 | * @var WebSnippet |
||
67 | */ |
||
68 | private $webSnippet; |
||
69 | |||
70 | /** |
||
71 | * The time that the project was originally created |
||
72 | * @var string |
||
73 | */ |
||
74 | private $created; |
||
75 | |||
76 | /** |
||
77 | * The unique identifier for the project. |
||
78 | * @var integer |
||
79 | */ |
||
80 | private $id; |
||
81 | |||
82 | /** |
||
83 | * Whether or not this project was created under Optimizely Classic. |
||
84 | * @var boolean |
||
85 | */ |
||
86 | private $isClassic; |
||
87 | |||
88 | /** |
||
89 | * The time the project was last modified |
||
90 | * @var string |
||
91 | */ |
||
92 | private $lastModified; |
||
93 | |||
94 | /** |
||
95 | * The token used to identify your mobile app to Optimizely. (mobile only) |
||
96 | * @var string |
||
97 | */ |
||
98 | private $socketToken; |
||
99 | |||
100 | /** |
||
101 | * A short description of the Project |
||
102 | * @var string |
||
103 | */ |
||
104 | private $description; |
||
105 | |||
106 | /** |
||
107 | * Constructor. |
||
108 | */ |
||
109 | 8 | public function __construct($options = array()) |
|
136 | |||
137 | /** |
||
138 | * Returns this object as array. |
||
139 | */ |
||
140 | 3 | public function toArray() |
|
168 | |||
169 | 7 | public function getName() |
|
173 | |||
174 | 7 | public function setName($name) |
|
178 | |||
179 | 5 | public function getAccountId() |
|
183 | |||
184 | 7 | public function setAccountId($accountId) |
|
188 | |||
189 | 4 | public function getConfidenceThreshold() |
|
193 | |||
194 | 3 | public function setConfidenceThreshold($confidenceThreshold) |
|
198 | |||
199 | 4 | public function getDcpServiceId() |
|
203 | |||
204 | 3 | public function setDcpServiceId($dcpServiceId) |
|
208 | |||
209 | 4 | public function getPlatform() |
|
213 | |||
214 | 4 | public function setPlatform($platform) |
|
218 | |||
219 | 4 | public function getSdks() |
|
223 | |||
224 | 2 | public function setSdks($sdks) |
|
228 | |||
229 | 4 | public function getStatus() |
|
233 | |||
234 | 3 | public function setStatus($status) |
|
238 | |||
239 | 5 | public function getWebSnippet() |
|
243 | |||
244 | 7 | public function setWebSnippet($webSnippet) |
|
248 | |||
249 | 5 | public function getCreated() |
|
253 | |||
254 | 7 | public function setCreated($created) |
|
258 | |||
259 | 5 | public function getId() |
|
263 | |||
264 | 7 | public function setId($id) |
|
268 | |||
269 | 5 | public function getIsClassic() |
|
273 | |||
274 | 6 | public function setIsClassic($isClassic) |
|
278 | |||
279 | 5 | public function getLastModified() |
|
283 | |||
284 | 6 | public function setLastModified($lastModified) |
|
288 | |||
289 | 5 | public function getSocketToken() |
|
293 | |||
294 | 6 | public function setSocketToken($socketToken) |
|
298 | |||
299 | 3 | public function getDescription() |
|
303 | |||
304 | public function setDescription($description) |
||
308 | } |
||
309 | |||
312 |