Conditions | 12 |
Paths | 9 |
Total Lines | 48 |
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 |
||
18 | public function validate($value, $type, Validator $validator) |
||
19 | { |
||
20 | Assert::type($type, ['array', 'string'], self::KEYWORD, $validator->getSchemaPath()); |
||
21 | |||
22 | if (is_array($type)) { |
||
23 | return $this->anyType($value, $type, $validator); |
||
24 | } |
||
25 | |||
26 | switch ($type) { |
||
27 | case 'object': |
||
28 | return $this->validateType($value, 'is_object', $validator); |
||
29 | case 'array': |
||
30 | return $this->validateType($value, 'is_array', $validator); |
||
31 | case 'boolean': |
||
32 | return $this->validateType($value, 'is_bool', $validator); |
||
33 | case 'null': |
||
34 | return $this->validateType($value, 'is_null', $validator); |
||
35 | case 'number': |
||
36 | return $this->validateType( |
||
37 | $value, |
||
38 | 'League\JsonGuard\is_json_number', |
||
39 | $validator |
||
40 | ); |
||
41 | case 'integer': |
||
42 | return $this->validateType( |
||
43 | $value, |
||
44 | 'League\JsonGuard\is_json_integer', |
||
45 | $validator |
||
46 | ); |
||
47 | case 'string': |
||
48 | return $this->validateType( |
||
49 | $value, |
||
50 | function ($value) { |
||
51 | if (is_string($value)) { |
||
52 | // Make sure the string isn't actually a number that was too large |
||
53 | // to be cast to an int on this platform. This will only happen if |
||
54 | // you decode JSON with the JSON_BIGINT_AS_STRING option. |
||
55 | if (!(ctype_digit($value) && bccomp($value, PHP_INT_MAX) === 1)) { |
||
56 | return true; |
||
57 | } |
||
58 | } |
||
59 | |||
60 | return false; |
||
61 | }, |
||
62 | $validator |
||
63 | ); |
||
64 | } |
||
65 | } |
||
66 | |||
104 |