| Conditions | 12 |
| Paths | 16 |
| Total Lines | 25 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 97 | public static function isSerialized($data) { |
||
| 98 | // if it isn't a string, it isn't serialized |
||
| 99 | if ( !is_string( $data ) ) |
||
| 100 | return false; |
||
| 101 | $data = trim( $data ); |
||
| 102 | if ( 'N;' == $data ) |
||
| 103 | return true; |
||
| 104 | if ( !preg_match( '/^([adObis]):/', $data, $badions ) ) |
||
| 105 | return false; |
||
| 106 | switch ( $badions[1] ) { |
||
| 107 | case 'a' : |
||
|
|
|||
| 108 | case 'O' : |
||
| 109 | case 's' : |
||
| 110 | if ( preg_match( "/^{$badions[1]}:[0-9]+:.*[;}]\$/s", $data ) ) |
||
| 111 | return true; |
||
| 112 | break; |
||
| 113 | case 'b' : |
||
| 114 | case 'i' : |
||
| 115 | case 'd' : |
||
| 116 | if ( preg_match( "/^{$badions[1]}:[0-9.E-]+;\$/", $data ) ) |
||
| 117 | return true; |
||
| 118 | break; |
||
| 119 | } |
||
| 120 | return false; |
||
| 121 | } |
||
| 122 | } |
||
| 123 |
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.