Complex classes like HttpRequestA 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 HttpRequestA, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | abstract class HttpRequestA extends BaseObject { |
||
16 | use GetRequestTrait; |
||
17 | use PostRequestTrait; |
||
18 | use CookieRequestTrait; |
||
19 | use FilesRequestTrait; |
||
20 | use SessionRequestTrait; |
||
21 | use AuthenticatedRequestTrait; |
||
22 | use ServerRequestTrait; |
||
23 | |||
24 | protected $sUri = null; |
||
25 | /** |
||
26 | * @var Url |
||
27 | */ |
||
28 | protected $oUri; |
||
29 | static private $aVarOrder = []; |
||
30 | |||
31 | protected $sAuthorization = ''; |
||
32 | protected $iContentLength = 0; // ? I don't think I'm interested in the length of the request |
||
33 | |||
34 | 18 | public function __construct() { |
|
48 | |||
49 | /** |
||
50 | * @return array |
||
51 | */ |
||
52 | 1 | public static function getVarOrder() { |
|
63 | |||
64 | /** |
||
65 | * @return array |
||
66 | */ |
||
67 | 1 | public function getVars() { |
|
89 | |||
90 | /** |
||
91 | * @param string $sVarName |
||
92 | * @throws Exception |
||
93 | * @return mixed |
||
94 | */ |
||
95 | 1 | public function getVar($sVarName) { |
|
119 | |||
120 | /** |
||
121 | * @param string $sContentType |
||
122 | * @return bool |
||
123 | */ |
||
124 | public static function validContentType($sContentType) { |
||
127 | |||
128 | /** |
||
129 | * @param string $sVarName |
||
130 | * @return bool |
||
131 | */ |
||
132 | 1 | public function hasVar($sVarName) { |
|
140 | |||
141 | /** |
||
142 | * @return bool |
||
143 | */ |
||
144 | 1 | public function isGet() { |
|
147 | |||
148 | /** |
||
149 | * @return bool |
||
150 | */ |
||
151 | 1 | public function isHead() { |
|
154 | |||
155 | /** |
||
156 | * @return bool |
||
157 | */ |
||
158 | 1 | public function isPost() { |
|
161 | |||
162 | /** |
||
163 | * @return bool |
||
164 | */ |
||
165 | 1 | public function isPut() { |
|
168 | |||
169 | /** |
||
170 | * @return bool |
||
171 | */ |
||
172 | 1 | public function isDelete() { |
|
175 | |||
176 | /** |
||
177 | * @param string $sMimeType |
||
178 | * @return bool |
||
179 | */ |
||
180 | 6 | public function accepts($sMimeType) { |
|
183 | |||
184 | /** |
||
185 | * Returns the REQUEST_URI which is used to get the URL Rewrite variables |
||
186 | * This will also remove the part of the path that is actually an existing path |
||
187 | * lighttpd: |
||
188 | * url.rewrite = ( |
||
189 | * "^/([^?]*)?(.*)$" => "/index.php$2" <- this doesn't look right to me |
||
190 | * ) |
||
191 | * |
||
192 | * @todo move to the UrlRWParser |
||
193 | * @param bool $bUrlDecode |
||
194 | * @return string |
||
195 | */ |
||
196 | 18 | public function getUri($bUrlDecode = false) { |
|
219 | |||
220 | /** |
||
221 | * @return Url |
||
222 | */ |
||
223 | 18 | public function getUriObject() { |
|
229 | |||
230 | 24 | static public function getDecodedVar($mVar) { |
|
240 | } |
||
241 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.