| Conditions | 13 |
| Paths | 12 |
| Total Lines | 34 |
| Code Lines | 26 |
| 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 |
||
| 38 | function is_serialized($data) |
||
| 39 | { |
||
| 40 | if (!is_string($data)) { |
||
| 41 | return false; |
||
| 42 | } |
||
| 43 | $data = trim($data); |
||
| 44 | if ('N;' == $data) { |
||
| 45 | return true; |
||
| 46 | } |
||
| 47 | $length = strlen($data); |
||
| 48 | if ($length < 4) { |
||
| 49 | return false; |
||
| 50 | } |
||
| 51 | if (':' !== $data[1]) { |
||
| 52 | return false; |
||
| 53 | } |
||
| 54 | $lastc = $data[$length - 1]; |
||
| 55 | if (';' !== $lastc && '}' !== $lastc) { |
||
| 56 | return false; |
||
| 57 | } |
||
| 58 | $token = $data[0]; |
||
| 59 | switch ($token) { |
||
| 60 | case 's': |
||
| 61 | return ('"' === $data[$length - 2]); |
||
| 62 | case 'a': |
||
| 63 | case 'O': |
||
| 64 | return (bool)preg_match("/^{$token}:[0-9]+:/s", $data); |
||
| 65 | case 'b': |
||
| 66 | case 'i': |
||
| 67 | case 'd': |
||
| 68 | return (bool)preg_match("/^{$token}:[0-9.E-]+;\$/", $data); |
||
| 69 | } |
||
| 70 | return false; |
||
| 71 | } |
||
| 72 | } |
||
| 102 |