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