| Conditions | 12 |
| Paths | 16 |
| Total Lines | 31 |
| Code Lines | 21 |
| 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 |
||
| 120 | public static function isSerialized($data): bool |
||
| 121 | { |
||
| 122 | // if it isn't a string, it isn't serialized |
||
| 123 | if (! is_string($data)) { |
||
| 124 | return false; |
||
| 125 | } |
||
| 126 | $data = trim($data); |
||
| 127 | if ('N;' == $data) { |
||
| 128 | return true; |
||
| 129 | } |
||
| 130 | if (! preg_match('/^([adObis]):/', $data, $badions)) { |
||
| 131 | return false; |
||
| 132 | } |
||
| 133 | switch ($badions[1]) { |
||
| 134 | case 'a': |
||
| 135 | case 'O': |
||
| 136 | case 's': |
||
| 137 | if (preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data)) { |
||
| 138 | return true; |
||
| 139 | } |
||
| 140 | break; |
||
| 141 | case 'b': |
||
| 142 | case 'i': |
||
| 143 | case 'd': |
||
| 144 | if (preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data)) { |
||
| 145 | return true; |
||
| 146 | } |
||
| 147 | break; |
||
| 148 | } |
||
| 149 | |||
| 150 | return false; |
||
| 151 | } |
||
| 154 |