| Conditions | 14 |
| Paths | 12 |
| Total Lines | 44 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 56 | protected function getType(&$value) |
||
| 57 | { |
||
| 58 | $type = self::T_UNKNOWN; |
||
| 59 | |||
| 60 | switch (true) { |
||
| 61 | // Recognize numeric values |
||
| 62 | case is_numeric($value): |
||
| 63 | if (false !== strpos($value, '.') || false !== stripos($value, 'e')) { |
||
| 64 | return self::T_FLOAT; |
||
| 65 | } |
||
| 66 | |||
| 67 | return self::T_INTEGER; |
||
| 68 | |||
| 69 | // Recognize quoted strings |
||
| 70 | case "'" === $value[0]: |
||
| 71 | $value = str_replace("''", "'", substr($value, 1, strlen($value) - 2)); |
||
| 72 | |||
| 73 | return self::T_STRING; |
||
| 74 | case '"' === $value[0]: |
||
| 75 | $value = str_replace('""', '"', substr($value, 1, strlen($value) - 2)); |
||
| 76 | |||
| 77 | return self::T_STRING; |
||
| 78 | case 'null' === $value: |
||
| 79 | return self::T_NULL; |
||
| 80 | // Recognize identifiers, aliased or qualified names |
||
| 81 | case ctype_alpha($value[0]) || '\\' === $value[0]: |
||
| 82 | return self::T_IDENTIFIER; |
||
| 83 | case ',' === $value: |
||
| 84 | return self::T_COMMA; |
||
| 85 | case '>' === $value: |
||
| 86 | return self::T_TYPE_END; |
||
| 87 | case '<' === $value: |
||
| 88 | return self::T_TYPE_START; |
||
| 89 | case ']' === $value: |
||
| 90 | return self::T_ARRAY_END; |
||
| 91 | case '[' === $value: |
||
| 92 | return self::T_ARRAY_START; |
||
| 93 | |||
| 94 | // Default |
||
| 95 | default: |
||
| 96 | // Do nothing |
||
| 97 | } |
||
| 98 | |||
| 99 | return $type; |
||
| 100 | } |
||
| 102 |