Conditions | 10 |
Paths | 10 |
Total Lines | 32 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
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 |
||
11 | public function validate($value, Constraint $constraint) |
||
12 | { |
||
13 | |||
14 | if (!$constraint instanceof IdentityNumber) { |
||
15 | throw new UnexpectedTypeException($constraint, IdentityNumber::class); |
||
|
|||
16 | } |
||
17 | |||
18 | if (null === $value || '' === $value) { |
||
19 | return; |
||
20 | } |
||
21 | |||
22 | $identityNumberArr = str_split($value); |
||
23 | $identityNumberCount = count($identityNumberArr); |
||
24 | $identityNumberSum = null; |
||
25 | $identityNumberCharacterType = false; |
||
26 | |||
27 | for ($i = 0; $i < $identityNumberCount; $i++) { |
||
28 | $identityNumber = $identityNumberArr[$i]; |
||
29 | if (!is_numeric($identityNumber)) { |
||
30 | $identityNumberCharacterType = true; |
||
31 | break; |
||
32 | } |
||
33 | if ($i !== $identityNumberCount - 1) { |
||
34 | $identityNumberSum += $identityNumber; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | |||
39 | if ($identityNumberCount !== 11 || $identityNumberCharacterType || str_split($identityNumberSum)[1] !== $identityNumberArr[$identityNumberCount - 1]) { |
||
40 | $this->context->buildViolation($constraint->message) |
||
41 | ->setParameter('{{ value }}', $value) |
||
42 | ->addViolation(); |
||
43 | } |
||
46 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths