Complex classes like UrlParserA 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 UrlParserA, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class UrlParserA extends BaseObject implements UrlParserInterface { |
||
| 8 | static protected $queryEncodingType = PHP_QUERY_RFC1738; |
||
| 9 | |||
| 10 | private $sUrl; |
||
| 11 | /** |
||
| 12 | * @var Url |
||
| 13 | */ |
||
| 14 | private $oUrl; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @param string $sUrl |
||
|
|
|||
| 18 | */ |
||
| 19 | public function __construct($sUrl = null) { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @return string |
||
| 25 | */ |
||
| 26 | public function __toString() { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * This is somewhat ugly. |
||
| 32 | * Returns an instance of the class on which the method is called |
||
| 33 | * @return Url |
||
| 34 | */ |
||
| 35 | public static function getCurrentUrl() { |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | 4 | public static function getRequestUri() { |
|
| 55 | |||
| 56 | /** |
||
| 57 | * @param string $sUrl |
||
| 58 | * @return bool |
||
| 59 | */ |
||
| 60 | 1 | public static function urlHasScheme($sUrl) { |
|
| 65 | |||
| 66 | /** |
||
| 67 | * @param Url $oUrl |
||
| 68 | * @param array $aParsed |
||
| 69 | * @return Url |
||
| 70 | */ |
||
| 71 | 1 | private static function loadParsedUrl($oUrl, $aParsed) { |
|
| 92 | |||
| 93 | /** |
||
| 94 | * This exists as the php::parse_url function sometimes breaks inexplicably |
||
| 95 | * @param string $sUrl |
||
| 96 | * @return Url |
||
| 97 | */ |
||
| 98 | 25 | protected static function parse_url($sUrl = null) { |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @param string $sUrl |
||
| 127 | */ |
||
| 128 | public function setUrl($sUrl) { |
||
| 132 | |||
| 133 | private function getSubdomainOf($sRootDomain) { |
||
| 139 | |||
| 140 | 1 | public static function getTldOf($sHost) { |
|
| 149 | |||
| 150 | public static function getCurrentHostName() { |
||
| 153 | |||
| 154 | 3 | public function getParentPath($iSteps = 0) { |
|
| 176 | |||
| 177 | 4 | public function setPath($sPath) { |
|
| 180 | |||
| 181 | 1 | public function getPath() { |
|
| 184 | |||
| 185 | /** |
||
| 186 | * @param string $sPath |
||
| 187 | * @return bool |
||
| 188 | */ |
||
| 189 | 1 | public static function isAbsolutePath($sPath) { |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @return Url |
||
| 195 | */ |
||
| 196 | 1 | static public function getSiteUri() { |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param int $iSteps |
||
| 202 | * @return string |
||
| 203 | * @internal param bool $bFull |
||
| 204 | */ |
||
| 205 | 3 | public function getCompleteParentUri($iSteps = 1) { |
|
| 214 | |||
| 215 | /** |
||
| 216 | * @return string |
||
| 217 | * @internal param bool $bFull |
||
| 218 | */ |
||
| 219 | 3 | public function getCompleteUri() { |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @param string $sUri |
||
| 225 | * @param string $sTermination |
||
| 226 | * @return bool |
||
| 227 | */ |
||
| 228 | 26 | public static function hasGoodTermination($sUri, $sTermination = '/') { |
|
| 232 | |||
| 233 | /** |
||
| 234 | * @param string $sUrl |
||
| 235 | * @return Url |
||
| 236 | */ |
||
| 237 | 18 | static public function url($sUrl) { |
|
| 240 | |||
| 241 | /** |
||
| 242 | * @param string $sPath |
||
| 243 | * @return string |
||
| 244 | */ |
||
| 245 | 42 | static public function normalizePath($sPath) { |
|
| 286 | } |
||
| 287 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.