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 |
||
100 | public static function isSerialized($data): bool |
||
101 | { |
||
102 | // if it isn't a string, it isn't serialized |
||
103 | if (! is_string($data)) { |
||
104 | return false; |
||
105 | } |
||
106 | $data = trim($data); |
||
107 | if ('N;' == $data) { |
||
108 | return true; |
||
109 | } |
||
110 | if (! preg_match('/^([adObis]):/', $data, $badions)) { |
||
111 | return false; |
||
112 | } |
||
113 | switch ($badions[1]) { |
||
114 | case 'a': |
||
115 | case 'O': |
||
116 | case 's': |
||
117 | if (preg_match("/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data)) { |
||
118 | return true; |
||
119 | } |
||
120 | break; |
||
121 | case 'b': |
||
122 | case 'i': |
||
123 | case 'd': |
||
124 | if (preg_match("/^{$badions[1]}:[0-9.E-]+;\$/", $data)) { |
||
125 | return true; |
||
126 | } |
||
127 | break; |
||
128 | } |
||
129 | |||
130 | return false; |
||
131 | } |
||
133 |