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 |
||
14 | class Project |
||
15 | { |
||
16 | /** |
||
17 | * The name of the project |
||
18 | * @var string |
||
19 | */ |
||
20 | private $name; |
||
21 | |||
22 | /** |
||
23 | * The account the project is associated with |
||
24 | * @var integer |
||
25 | */ |
||
26 | private $accountId; |
||
27 | |||
28 | /** |
||
29 | * The significance level at which you would like to declare winning and |
||
30 | * losing variations. A lower number minimizes the time needed to declare a |
||
31 | * winning or losing variation, but increases the risk that your results |
||
32 | * aren't true winners and losers. The precision for this number is up to 4 |
||
33 | * decimal places. |
||
34 | * |
||
35 | * @var number |
||
36 | */ |
||
37 | private $confidenceThreshold; |
||
38 | |||
39 | /** |
||
40 | * The ID of a Dynamic Customer Profile Service associated with this project. |
||
41 | * @var integer |
||
42 | */ |
||
43 | private $dcpServiceId; |
||
44 | |||
45 | /** |
||
46 | * The platform of the project. Can be 'web', 'ios', 'android' or 'custom'. |
||
47 | * @var string |
||
48 | */ |
||
49 | private $platform; |
||
50 | |||
51 | /** |
||
52 | * The current status of the project. Can be 'active' or 'archived'. |
||
53 | * @var string |
||
54 | */ |
||
55 | private $status; |
||
56 | |||
57 | /** |
||
58 | * Web snippet-specific configuration for this project. |
||
59 | * @var WebSnippet |
||
60 | */ |
||
61 | private $webSnippet; |
||
62 | |||
63 | /** |
||
64 | * The time that the project was originally created |
||
65 | * @var string |
||
66 | */ |
||
67 | private $created; |
||
68 | |||
69 | /** |
||
70 | * The unique identifier for the project. |
||
71 | * @var integer |
||
72 | */ |
||
73 | private $id; |
||
74 | |||
75 | /** |
||
76 | * Whether or not this project was created under Optimizely Classic. |
||
77 | * @var boolean |
||
78 | */ |
||
79 | private $isClassic; |
||
80 | |||
81 | /** |
||
82 | * The time the project was last modified |
||
83 | * @var string |
||
84 | */ |
||
85 | private $lastModified; |
||
86 | |||
87 | /** |
||
88 | * The token used to identify your mobile app to Optimizely. (mobile only) |
||
89 | * @var string |
||
90 | */ |
||
91 | private $socketToken; |
||
92 | |||
93 | /** |
||
94 | * Constructor. |
||
95 | */ |
||
96 | 7 | public function __construct($options = array()) |
|
121 | |||
122 | /** |
||
123 | * Returns this object as array. |
||
124 | */ |
||
125 | 3 | public function toArray() |
|
151 | |||
152 | 7 | public function getName() |
|
156 | |||
157 | 7 | public function setName($name) |
|
161 | |||
162 | 5 | public function getAccountId() |
|
166 | |||
167 | 7 | public function setAccountId($accountId) |
|
171 | |||
172 | 4 | public function getConfidenceThreshold() |
|
176 | |||
177 | 3 | public function setConfidenceThreshold($confidenceThreshold) |
|
181 | |||
182 | 4 | public function getDcpServiceId() |
|
186 | |||
187 | 3 | public function setDcpServiceId($dcpServiceId) |
|
191 | |||
192 | 4 | public function getPlatform() |
|
196 | |||
197 | 3 | public function setPlatform($platform) |
|
201 | |||
202 | 4 | public function getStatus() |
|
206 | |||
207 | 3 | public function setStatus($status) |
|
211 | |||
212 | 5 | public function getWebSnippet() |
|
216 | |||
217 | 7 | public function setWebSnippet($webSnippet) |
|
221 | |||
222 | 5 | public function getCreated() |
|
226 | |||
227 | 7 | public function setCreated($created) |
|
231 | |||
232 | 5 | public function getId() |
|
236 | |||
237 | 7 | public function setId($id) |
|
241 | |||
242 | 5 | public function getIsClassic() |
|
246 | |||
247 | 6 | public function setIsClassic($isClassic) |
|
251 | |||
252 | 5 | public function getLastModified() |
|
256 | |||
257 | 6 | public function setLastModified($lastModified) |
|
261 | |||
262 | 5 | public function getSocketToken() |
|
266 | |||
267 | 6 | public function setSocketToken($socketToken) |
|
271 | } |
||
272 | |||
275 |
According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.
}
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.