Complex classes like Utils 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 Utils, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class Utils |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Gets upper case word admong a string from the end or from the beginning part |
||
| 11 | * @param string $optionValue |
||
| 12 | * @param string $string the string from which we can extract the part |
||
| 13 | * @return string |
||
| 14 | */ |
||
| 15 | 472 | public static function getPart($optionValue, $string) |
|
| 62 | /** |
||
| 63 | * Get content from url using a proxy or not |
||
| 64 | * @param string $url |
||
| 65 | * @param string $basicAuthLogin |
||
| 66 | * @param string $basicAuthPassword |
||
| 67 | * @param string $proxyHost |
||
| 68 | * @param string $proxyPort |
||
| 69 | * @param string $proxyLogin |
||
| 70 | * @param string $proxyPassword |
||
| 71 | * @param array $contextOptions |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | 8 | public static function getContentFromUrl($url, $basicAuthLogin = null, $basicAuthPassword = null, $proxyHost = null, $proxyPort = null, $proxyLogin = null, $proxyPassword = null, array $contextOptions = array()) |
|
| 83 | /** |
||
| 84 | * @param string $url |
||
| 85 | * @param string $basicAuthLogin |
||
| 86 | * @param string $basicAuthPassword |
||
| 87 | * @param string $proxyHost |
||
| 88 | * @param string $proxyPort |
||
| 89 | * @param string $proxyLogin |
||
| 90 | * @param string $proxyPassword |
||
| 91 | * @param array $contextOptions |
||
| 92 | * @return string[] |
||
| 93 | */ |
||
| 94 | 24 | public static function getContentFromUrlContextOptions($url, $basicAuthLogin = null, $basicAuthPassword = null, $proxyHost = null, $proxyPort = null, $proxyLogin = null, $proxyPassword = null, array $contextOptions = array()) |
|
| 119 | /** |
||
| 120 | * Returns the value with good type |
||
| 121 | * @param mixed $value the value |
||
| 122 | * @return mixed |
||
| 123 | */ |
||
| 124 | 580 | public static function getValueWithinItsType($value, $knownType = null) |
|
| 151 | /** |
||
| 152 | * @param string $origin |
||
| 153 | * @param string $destination |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | 188 | public static function resolveCompletePath($origin, $destination) |
|
| 197 | /** |
||
| 198 | * Clean comment |
||
| 199 | * @param string $comment the comment to clean |
||
| 200 | * @param string $glueSeparator ths string to use when gathering values |
||
| 201 | * @param bool $uniqueValues indicates if comment values must be unique or not |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | 136 | public static function cleanComment($comment, $glueSeparator = ',', $uniqueValues = true) |
|
| 211 | /** |
||
| 212 | * Clean a string to make it valid as PHP variable |
||
| 213 | * See more about the used regular expression at {@link http://www.regular-expressions.info/unicode.html}: |
||
| 214 | * - \p{L} for any valid letter |
||
| 215 | * - \p{N} for any valid number |
||
| 216 | * - /u for suporting unicode |
||
| 217 | * @param string $string the string to clean |
||
| 218 | * @param bool $keepMultipleUnderscores optional, allows to keep the multiple consecutive underscores |
||
| 219 | * @return string |
||
| 220 | */ |
||
| 221 | 532 | public static function cleanString($string, $keepMultipleUnderscores = true) |
|
| 229 | /** |
||
| 230 | * @param string $namespacedClassName |
||
| 231 | * @return string |
||
| 232 | */ |
||
| 233 | 196 | public static function removeNamespace($namespacedClassName) |
|
| 238 | /** |
||
| 239 | * @param string $directory |
||
| 240 | * @param int $permissions |
||
| 241 | * @return bool |
||
| 242 | */ |
||
| 243 | 220 | public static function createDirectory($directory, $permissions = 0775) |
|
| 250 | } |
||
| 251 |