| Total Complexity | 44 |
| Total Lines | 143 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like CodeUtils 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.
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 CodeUtils, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 13 | class CodeUtils { |
||
| 14 | |||
| 15 | public static function cleanParameters($parameters) { |
||
| 42 | } |
||
| 43 | |||
| 44 | public static function getParametersForRoute($parameters) { |
||
| 45 | $tmpResult = [ ]; |
||
| 46 | $params = \explode ( ",", $parameters ); |
||
| 47 | foreach ( $params as $param ) { |
||
| 48 | $param = \trim ( $param ); |
||
| 49 | $list = \explode ( "=", $param ); |
||
| 50 | if (isset ( $list [0] )) { |
||
| 51 | $var = $list [0]; |
||
| 52 | } |
||
| 53 | if (isset ( $list [1] )) { |
||
| 54 | $value = $list [1]; |
||
| 55 | } |
||
| 56 | if (isset ( $var ) && isset ( $value )) { |
||
| 57 | break; |
||
| 58 | } elseif (isset ( $var )) { |
||
| 59 | $var = self::unCheckVar ( $var ); |
||
| 60 | $tmpResult [] = '{' . $var . '}'; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | return $tmpResult; |
||
| 64 | } |
||
| 65 | |||
| 66 | public static function checkVar($var, $prefix = '$') { |
||
| 74 | } |
||
| 75 | |||
| 76 | public static function unCheckVar($var, $prefix = '$') { |
||
| 77 | if (UString::isNull ( $var )) |
||
| 78 | return ""; |
||
| 79 | $var = \trim ( $var ); |
||
| 80 | if (UString::startswith ( $var, $prefix )) { |
||
| 81 | $var = \substr ( $var, \sizeof ( $prefix ) ); |
||
| 82 | } |
||
| 83 | return $var; |
||
| 84 | } |
||
| 85 | |||
| 86 | public static function indent($code, $count = 2) { |
||
| 90 | } |
||
| 91 | |||
| 92 | public static function isValidCode($code) { |
||
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * |
||
| 115 | * @see https://stackoverflow.com/questions/2372624/get-current-php-executable-from-within-script |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | public static function getPHPExecutable() { |
||
| 158 |