Conditions | 8 |
Paths | 8 |
Total Lines | 51 |
Code Lines | 39 |
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 |
||
53 | public function validate($value, $parameter, Validator $validator) |
||
54 | { |
||
55 | Assert::type($parameter, 'string', self::KEYWORD, $validator->getSchemaPath()); |
||
56 | |||
57 | if (isset($this->extensions[$parameter])) { |
||
58 | return $this->extensions[$parameter]->validate($value, $validator); |
||
59 | } |
||
60 | |||
61 | switch ($parameter) { |
||
62 | case 'date-time': |
||
63 | return self::validateRegex( |
||
64 | $value, |
||
65 | self::DATE_TIME_PATTERN, |
||
66 | $validator |
||
67 | ); |
||
68 | case 'uri': |
||
69 | return self::validateFilter( |
||
70 | $value, |
||
71 | FILTER_VALIDATE_URL, |
||
72 | null, |
||
73 | $validator |
||
74 | ); |
||
75 | case 'email': |
||
76 | return self::validateFilter( |
||
77 | $value, |
||
78 | FILTER_VALIDATE_EMAIL, |
||
79 | null, |
||
80 | $validator |
||
81 | ); |
||
82 | case 'ipv4': |
||
83 | return self::validateFilter( |
||
84 | $value, |
||
85 | FILTER_VALIDATE_IP, |
||
86 | FILTER_FLAG_IPV4, |
||
87 | $validator |
||
88 | ); |
||
89 | case 'ipv6': |
||
90 | return self::validateFilter( |
||
91 | $value, |
||
92 | FILTER_VALIDATE_IP, |
||
93 | FILTER_FLAG_IPV6, |
||
94 | $validator |
||
95 | ); |
||
96 | case 'hostname': |
||
97 | return self::validateRegex( |
||
98 | $value, |
||
99 | self::HOST_NAME_PATTERN, |
||
100 | $validator |
||
101 | ); |
||
102 | } |
||
103 | } |
||
104 | |||
148 |