| Conditions | 30 |
| Paths | 53 |
| Total Lines | 88 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 68 | public static function getAvailableClassMethods (string $code, string $class): array |
||
| 69 | {
|
||
| 70 | $code = self::stripComments ($code); |
||
| 71 | |||
| 72 | $split1 = $split2 = false; |
||
| 73 | |||
| 74 | $len = strlen ($code); |
||
| 75 | $classLen = strlen ($class); |
||
| 76 | |||
| 77 | $class_predefined = false; |
||
| 78 | $class_close = null; |
||
| 79 | |||
| 80 | $methods = []; |
||
| 81 | |||
| 82 | for ($i = 0; $i < $len; ++$i) |
||
| 83 | {
|
||
| 84 | if ($code[$i] == '\'' && !$split2) |
||
| 85 | $split1 = !$split1; |
||
| 86 | |||
| 87 | elseif ($code[$i] == '"' && !$split1) |
||
| 88 | $split2 = !$split2; |
||
| 89 | |||
| 90 | elseif (!$split1 && !$split2) |
||
| 91 | {
|
||
| 92 | if ($code[$i] == 'c' && substr ($code, $i, 5) == 'class') |
||
| 93 | {
|
||
| 94 | for ($j = $i + 5; $j < $len; ++$j) |
||
| 95 | if (in_array ($code[$j], ["\n", "\r", "\t", ' '])) |
||
| 96 | continue; |
||
| 97 | |||
| 98 | else |
||
| 99 | {
|
||
| 100 | if (substr ($code, $j, $classLen) == $class) |
||
| 101 | $class_predefined = true; |
||
| 102 | |||
| 103 | $i = $j; |
||
| 104 | |||
| 105 | break; |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | elseif ($class_predefined == true) |
||
| 110 | {
|
||
| 111 | if ($code[$i] == 'p' && substr ($code, $i, 6) == 'public') |
||
| 112 | {
|
||
| 113 | for ($j = $i + 6; $j < $len; ++$j) |
||
| 114 | if (!in_array ($code[$j], ["\n", "\r", "\t", ' '])) |
||
| 115 | break; |
||
| 116 | |||
| 117 | if ($code[$j] == 's' && substr ($code, $j, 6) == 'static') |
||
| 118 | for ($j = $j + 6; $j < $len; ++$j) |
||
| 119 | if (!in_array ($code[$j], ["\n", "\r", "\t", ' '])) |
||
| 120 | break; |
||
| 121 | |||
| 122 | if ($code[$j] == 'f' && substr ($code, $j, 8) == 'function') |
||
| 123 | {
|
||
| 124 | for ($j = $j + 8; $j < $len; ++$j) |
||
| 125 | if (in_array ($code[$j], ["\n", "\r", "\t", ' '])) |
||
| 126 | continue; |
||
| 127 | |||
| 128 | else |
||
| 129 | {
|
||
| 130 | $i = $j; |
||
| 131 | $methods[] = trim (substr ($code, $j, strpos ($code, '(', $j) - $j));
|
||
| 132 | |||
| 133 | break; |
||
| 134 | } |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | elseif ($code[$i] == '{')
|
||
| 139 | {
|
||
| 140 | if ($class_close === null) |
||
| 141 | $class_close = 1; |
||
| 142 | |||
| 143 | else ++$class_close; |
||
| 144 | } |
||
| 145 | |||
| 146 | elseif ($code[$i] == '}') |
||
| 147 | --$class_close; |
||
| 148 | |||
| 149 | if ($class_close === 0) |
||
| 150 | return $methods; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | return $methods; |
||
| 156 | } |
||
| 187 |