Complex classes like AbstractEntryPoint 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 AbstractEntryPoint, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
11 | abstract class AbstractEntryPoint implements EPInterface { |
||
12 | |||
13 | /** |
||
14 | * Whether or not Authentication is Required |
||
15 | * @var bool |
||
16 | */ |
||
17 | protected $_AUTH_REQUIRED = true; |
||
18 | |||
19 | /** |
||
20 | * The default Module for the EntryPoint |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $_MODULE; |
||
24 | |||
25 | /** |
||
26 | * The URL for the EntryPoint |
||
27 | * - When configuring URL you define URL Parameters with $variables |
||
28 | * Examples: |
||
29 | * - Forecasts/$record_id |
||
30 | * - $module Variable is a keyword to place the Module property into the URL |
||
31 | * Examples: |
||
32 | * - $module/$record |
||
33 | * - Options property is used to replace variables in the order in which they are passed |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $_URL; |
||
38 | |||
39 | /** |
||
40 | * An array of Required Data properties that should be passed in the Request |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $_REQUIRED_DATA; |
||
44 | |||
45 | /** |
||
46 | * The configured URL for the EntryPoint |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $url; |
||
50 | |||
51 | /** |
||
52 | * The configured Module for the EntryPoint |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $Module; |
||
56 | |||
57 | /** |
||
58 | * The passed in Options for the EntryPoint |
||
59 | * - If $module variable is used in $_URL static property, then 1st option will be used as Module |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $Options = array(); |
||
63 | |||
64 | /** |
||
65 | * The data being passed to the API EntryPoint |
||
66 | * @var mixed - array or Std Object |
||
67 | */ |
||
68 | protected $Data; |
||
69 | |||
70 | /** |
||
71 | * The Request Object, used by the EntryPoint to submit the data |
||
72 | * @var Object |
||
73 | */ |
||
74 | protected $Request; |
||
75 | |||
76 | /** |
||
77 | * The Response Object, returned by the Request Object |
||
78 | * @var Object |
||
79 | */ |
||
80 | protected $Response; |
||
81 | |||
82 | /** |
||
83 | * Access Token for authentication |
||
84 | * @var string |
||
85 | */ |
||
86 | protected $accessToken; |
||
87 | |||
88 | public function __construct($url,$options = array()){ |
||
103 | |||
104 | /** |
||
105 | * @inheritdoc |
||
106 | */ |
||
107 | public function module($module){ |
||
111 | |||
112 | /** |
||
113 | * @inheritdoc |
||
114 | */ |
||
115 | public function options(array $options){ |
||
119 | |||
120 | /** |
||
121 | * @inheritdoc |
||
122 | */ |
||
123 | public function data(array $data){ |
||
128 | |||
129 | /** |
||
130 | * @inheritdoc |
||
131 | */ |
||
132 | public function execute(){ |
||
143 | |||
144 | /** |
||
145 | * @inheritdoc |
||
146 | */ |
||
147 | public function authRequired() { |
||
150 | |||
151 | /** |
||
152 | * @inheritdoc |
||
153 | */ |
||
154 | public function configureAuth($accessToken) { |
||
161 | |||
162 | /** |
||
163 | * @inheritdoc |
||
164 | */ |
||
165 | public function getModule() { |
||
168 | |||
169 | /** |
||
170 | * @inheritdoc |
||
171 | */ |
||
172 | public function getData(){ |
||
175 | |||
176 | /** |
||
177 | * @inheritdoc |
||
178 | */ |
||
179 | public function getURL(){ |
||
182 | |||
183 | /** |
||
184 | * @inheritdoc |
||
185 | */ |
||
186 | public function getResponse(){ |
||
189 | |||
190 | /** |
||
191 | * @inheritdoc |
||
192 | */ |
||
193 | public function getRequest(){ |
||
196 | |||
197 | /** |
||
198 | * Configures the URL, by updating any variable placeholders in the URL property on the EntryPoint |
||
199 | * - Replaces $module with $this->Module |
||
200 | * - Replaces all other variables starting with $, with options in the order they were given |
||
201 | */ |
||
202 | protected function configureURL(){ |
||
232 | |||
233 | /** |
||
234 | * Setup the Request Object property, setup on initial Construct of EntryPoint |
||
235 | */ |
||
236 | protected function setupRequest(){ |
||
239 | |||
240 | /** |
||
241 | * Setup the Response Object Property, not called until after Request Execution |
||
242 | */ |
||
243 | protected function setupResponse(){ |
||
246 | |||
247 | /** |
||
248 | * Verify URL variables have been removed, and that valid number of options were passed. |
||
249 | * @return bool |
||
250 | * @throws EntryPointException |
||
251 | */ |
||
252 | protected function verifyURL(){ |
||
269 | |||
270 | /** |
||
271 | * Validate Required Data for the Request |
||
272 | * @return bool |
||
273 | * @throws EntryPointException |
||
274 | */ |
||
275 | protected function validateData(){ |
||
294 | |||
295 | } |