Conditions | 10 |
Paths | 6 |
Total Lines | 25 |
Code Lines | 13 |
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 |
||
48 | public function validate($value, Constraint $constraint) |
||
49 | { |
||
50 | if (!$constraint instanceof UrlOrBuiltin) { |
||
51 | throw new UnexpectedTypeException($constraint, UrlOrBuiltin::class); |
||
52 | } |
||
53 | |||
54 | if (null === $value || '' === $value) { |
||
55 | return; |
||
56 | } |
||
57 | if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) { |
||
58 | throw new UnexpectedValueException($value, 'string'); |
||
59 | } |
||
60 | $value = (string) $value; |
||
61 | if ('' === $value) { |
||
62 | return; |
||
63 | } |
||
64 | |||
65 | //After the %PLACEHOLDER% comes a slash, so we can check if we have a placholder via explode |
||
66 | $tmp = explode('/', $value); |
||
67 | //Builtins must have a %PLACEHOLDER% construction |
||
68 | if (!empty($tmp) && in_array($tmp[0], $constraint->allowed_placeholders, false)) { |
||
69 | return; |
||
70 | } |
||
71 | |||
72 | parent::validate($value, $constraint); // TODO: Change the autogenerated stub |
||
73 | } |
||
76 | } |