Complex classes like HttpResponseA 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 HttpResponseA, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | abstract class HttpResponseA extends BaseObject { |
||
18 | use HttpHeadersTrait; |
||
19 | |||
20 | private $sServerProtocol; |
||
21 | private $iStatus; |
||
22 | private $aAllow = array(HttpRequestTypes::GET, HttpRequestTypes::POST, HttpRequestTypes::PUT, HttpRequestTypes::DELETE); |
||
23 | private $sCacheControl; |
||
24 | private $sContentEncoding; |
||
25 | private $sContentLanguage; |
||
26 | private $iContentLength; |
||
27 | private $sContentLocation; |
||
28 | private $sContentDisposition; |
||
29 | private $sContentMd5; |
||
30 | private $sDate; |
||
31 | private $sETag; |
||
32 | private $sExpires; |
||
33 | private $sLastModified; |
||
34 | private $sLocation; |
||
35 | private $oView; |
||
36 | |||
37 | protected $aHeaders = []; |
||
38 | protected $sContentType; |
||
39 | |||
40 | 1 | public function __construct() { |
|
47 | |||
48 | 22 | public function setStatus($iStatus) { |
|
55 | |||
56 | /** |
||
57 | * @param string $sValue |
||
58 | * @return void |
||
59 | */ |
||
60 | 1 | public function setLocation($sValue) { |
|
63 | |||
64 | 1 | public function addHeader($sName, $sValue) { |
|
67 | |||
68 | /** |
||
69 | * @param string $sValue |
||
70 | * @return void |
||
71 | */ |
||
72 | 2 | public function setCacheControl($sValue) { |
|
75 | |||
76 | /** |
||
77 | * @param string $sValue |
||
78 | * @return void |
||
79 | */ |
||
80 | 2 | public function setContentEncoding($sValue) { |
|
83 | |||
84 | /** |
||
85 | * @param string $sValue |
||
86 | * @return void |
||
87 | */ |
||
88 | 2 | public function setContentLanguage($sValue) { |
|
91 | |||
92 | /** |
||
93 | * @param integer $iValue |
||
94 | * @return void |
||
95 | */ |
||
96 | 2 | public function setContentLength($iValue) { |
|
99 | |||
100 | /** |
||
101 | * @param string $sValue |
||
102 | * @return void |
||
103 | */ |
||
104 | 2 | public function setContentLocation($sValue) { |
|
107 | |||
108 | /** |
||
109 | * @param string $sValue |
||
110 | * @return void |
||
111 | */ |
||
112 | 2 | public function setContentDisposition($sValue) { |
|
115 | |||
116 | /** |
||
117 | * @param string $sValue |
||
118 | * @return void |
||
119 | */ |
||
120 | 2 | public function setContentMd5($sValue) { |
|
123 | |||
124 | /** |
||
125 | * @param string $sValue |
||
126 | * @return void |
||
127 | */ |
||
128 | 2 | public function setContentType($sValue) { |
|
131 | |||
132 | /** |
||
133 | * @param string $sValue |
||
134 | * @return void |
||
135 | */ |
||
136 | 2 | public function setDate($sValue) { |
|
139 | |||
140 | /** |
||
141 | * @param string $sValue |
||
142 | * @return void |
||
143 | */ |
||
144 | 1 | public function setETag($sValue) { |
|
147 | |||
148 | /** |
||
149 | * @param string $sValue |
||
150 | * @return void |
||
151 | */ |
||
152 | 2 | public function setExpires($sValue) { |
|
155 | |||
156 | /** |
||
157 | * @param string $sValue |
||
158 | * @return void |
||
159 | */ |
||
160 | 2 | public function setLastModified($sValue) { |
|
163 | |||
164 | /** |
||
165 | * @return string |
||
166 | */ |
||
167 | 1 | public function getLocation() { |
|
170 | |||
171 | /** |
||
172 | * @return string |
||
173 | */ |
||
174 | 1 | public function getCacheControl() { |
|
177 | |||
178 | /** |
||
179 | * @return string |
||
180 | */ |
||
181 | 1 | public function getContentEncoding() { |
|
184 | |||
185 | /** |
||
186 | * @return string |
||
187 | */ |
||
188 | 1 | public function getContentLanguage() { |
|
191 | |||
192 | /** |
||
193 | * @return integer |
||
194 | */ |
||
195 | 1 | public function getContentLength() { |
|
198 | |||
199 | /** |
||
200 | * @return string |
||
201 | */ |
||
202 | 1 | public function getContentLocation() { |
|
205 | |||
206 | /** |
||
207 | * @return string |
||
208 | */ |
||
209 | 1 | public function getContentDisposition() { |
|
212 | |||
213 | /** |
||
214 | * @return string |
||
215 | */ |
||
216 | 1 | public function getContentMd5() { |
|
219 | |||
220 | /** |
||
221 | * @return string |
||
222 | */ |
||
223 | 1 | public function getContentType() { |
|
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | 1 | public function getDate() { |
|
233 | |||
234 | /** |
||
235 | * @return string |
||
236 | */ |
||
237 | 1 | public function getETag() { |
|
240 | |||
241 | /** |
||
242 | * @return string |
||
243 | */ |
||
244 | 1 | public function getExpires() { |
|
247 | |||
248 | /** |
||
249 | * @return string |
||
250 | */ |
||
251 | 1 | public function getLastModified() { |
|
254 | |||
255 | /** |
||
256 | * @return string |
||
257 | */ |
||
258 | 1 | public function getServerProtocol() { |
|
261 | |||
262 | /** |
||
263 | * @return array |
||
264 | */ |
||
265 | 2 | protected function getCustomHeaders() { |
|
268 | |||
269 | /** |
||
270 | * @param string $sProtocol |
||
271 | * @param int $iStatus |
||
272 | * @return string |
||
273 | */ |
||
274 | 1 | public static function getHttpStatusString($sProtocol, $iStatus) { |
|
277 | |||
278 | /** |
||
279 | * @return int |
||
280 | */ |
||
281 | 1 | public function getStatus() { |
|
284 | |||
285 | /** |
||
286 | * @param ViewA $oView |
||
287 | * @return string |
||
|
|||
288 | */ |
||
289 | 1 | public function setView(ViewA $oView) { |
|
292 | |||
293 | /** |
||
294 | * @returns ViewA |
||
295 | */ |
||
296 | 1 | public function getView() { |
|
302 | |||
303 | /** |
||
304 | * @return string |
||
305 | * @throws ExceptionResponse |
||
306 | */ |
||
307 | public function getOutput() { |
||
333 | |||
334 | 22 | public function isSuccess() { |
|
337 | |||
338 | 22 | public function isRedirect() { |
|
341 | |||
342 | 22 | public function isUserError() { |
|
345 | |||
346 | 22 | public function isServerError() { |
|
349 | |||
350 | 22 | public function isError() { |
|
353 | } |
||
354 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.