| Conditions | 12 |
| Paths | 50 |
| Total Lines | 39 |
| Code Lines | 32 |
| 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 |
||
| 16 | public static function readString($types, &$data) |
||
| 17 | { |
||
| 18 | if (!is_array($types)) { |
||
| 19 | $types = array($types); |
||
| 20 | } |
||
| 21 | $ok = false; |
||
| 22 | foreach ($types as $type) { |
||
| 23 | switch ($type) { |
||
| 24 | case self::OBJECT: |
||
| 25 | break; |
||
| 26 | case self::ARR: |
||
| 27 | break; |
||
| 28 | case self::STRING: |
||
| 29 | $ok = true; |
||
| 30 | break; |
||
| 31 | case self::NUMBER: |
||
| 32 | $newData = filter_var($data, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE); |
||
| 33 | $ok = is_float($newData); |
||
| 34 | break; |
||
| 35 | case self::INTEGER: |
||
| 36 | $newData = filter_var($data, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE); |
||
| 37 | $ok = is_int($newData); |
||
| 38 | break; |
||
| 39 | case self::BOOLEAN: |
||
| 40 | $newData = filter_var($data, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
||
| 41 | $ok = is_bool($data); |
||
| 42 | break; |
||
| 43 | case self::NULL: |
||
| 44 | break; |
||
| 45 | } |
||
| 46 | if ($ok) { |
||
| 47 | if (isset($newData)) { |
||
| 48 | $data = $newData; |
||
| 49 | } |
||
| 50 | return true; |
||
| 51 | } |
||
| 52 | } |
||
| 53 | return false; |
||
| 54 | } |
||
| 55 | |||
| 94 | } |