| Conditions | 16 |
| Paths | 54 |
| Total Lines | 38 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 32 |
| CRAP Score | 16 |
| 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 |
||
| 58 | 3257 | public static function isValid($types, $data, $version) |
|
| 59 | { |
||
| 60 | 3257 | if (!is_array($types)) { |
|
| 61 | 2824 | $types = array($types); |
|
| 62 | } |
||
| 63 | 3257 | $ok = false; |
|
| 64 | 3257 | foreach ($types as $type) { |
|
| 65 | switch ($type) { |
||
| 66 | 3257 | case self::OBJECT: |
|
| 67 | 3237 | $ok = is_object($data); |
|
| 68 | 3237 | break; |
|
| 69 | 2707 | case self::ARR: |
|
| 70 | 899 | $ok = is_array($data); |
|
| 71 | 899 | break; |
|
| 72 | 2579 | case self::STRING: |
|
| 73 | 1168 | $ok = is_string($data); |
|
| 74 | 1168 | break; |
|
| 75 | 1748 | case self::INTEGER: |
|
| 76 | 753 | $ok = is_int($data) |
|
| 77 | 197 | || (is_float($data) |
|
| 78 | 34 | && ((ceil($data) === $data && $version !== Schema::VERSION_DRAFT_04) // float without fraction is int |
|
| 79 | 753 | || abs($data) > PHP_INT_MAX)); // big float accepted for int |
|
| 80 | 753 | break; |
|
| 81 | 1212 | case self::NUMBER: |
|
| 82 | 507 | $ok = is_int($data) || is_float($data); |
|
| 83 | 507 | break; |
|
| 84 | 866 | case self::BOOLEAN: |
|
| 85 | 815 | $ok = is_bool($data); |
|
| 86 | 815 | break; |
|
| 87 | 53 | case self::NULL: |
|
| 88 | 53 | $ok = null === $data; |
|
| 89 | 53 | break; |
|
| 90 | } |
||
| 91 | 3257 | if ($ok) { |
|
| 92 | 3255 | return true; |
|
| 93 | } |
||
| 94 | } |
||
| 95 | 696 | return false; |
|
| 96 | } |
||
| 99 | } |