| Conditions | 8 | 
| Paths | 6 | 
| Total Lines | 27 | 
| Code Lines | 13 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 12 | 
| CRAP Score | 8.1867 | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php  | 
            ||
| 20 | 19 | public function validate(mixed $value, object $rule, ValidatorInterface $validator, ?ValidationContext $context = null): Result  | 
            |
| 21 |     { | 
            ||
| 22 | 19 | $result = new Result();  | 
            |
| 23 | |||
| 24 | 19 |         if (!is_countable($value)) { | 
            |
| 25 | $result->addError($rule->message);  | 
            ||
| 26 | |||
| 27 | return $result;  | 
            ||
| 28 | }  | 
            ||
| 29 | |||
| 30 | 19 | $count = count($value);  | 
            |
| 31 | |||
| 32 | 19 |         if ($rule->exactly !== null && $count !== $rule->exactly) { | 
            |
| 33 | 1 | $result->addError($rule->notExactlyMessage, ['exactly' => $rule->exactly]);  | 
            |
| 34 | |||
| 35 | 1 | return $result;  | 
            |
| 36 | }  | 
            ||
| 37 | |||
| 38 | 18 |         if ($rule->min !== null && $count < $rule->min) { | 
            |
| 39 | 9 | $result->addError($rule->tooFewItemsMessage, ['min' => $rule->min]);  | 
            |
| 40 | }  | 
            ||
| 41 | |||
| 42 | 18 |         if ($rule->max !== null && $count > $rule->max) { | 
            |
| 43 | 2 | $result->addError($rule->tooManyItemsMessage, ['max' => $rule->max]);  | 
            |
| 44 | }  | 
            ||
| 45 | |||
| 46 | 18 | return $result;  | 
            |
| 47 | }  | 
            ||
| 49 | 
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: