Passed
Push — master ( ea62c3...cd2ef0 )
by Bruno
09:11
created

MinLength::getMetadata()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Validator;
4
5
use Formularium\Exception\ValidatorException;
6
use Formularium\Field;
7
use Formularium\Model;
8
use Formularium\ValidatorInterface;
9
use Formularium\ValidatorMetadata;
10
11
class MinLength implements ValidatorInterface
12
{
13
    public function validate($value, array $validators = [], Model $model = null)
14
    {
15
        if (!is_string($value)) {
16
            throw new \Formularium\Exception\ValidatorException('Expected a string.');
17
        }
18
19
        $maxlength = $options['value'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $options seems to be never defined.
Loading history...
Unused Code introduced by
The assignment to $maxlength is dead and can be removed.
Loading history...
20
        if (mb_strlen($value) < $options[self::MIN_LENGTH]) {
0 ignored issues
show
Bug introduced by
The constant Formularium\Validator\MinLength::MIN_LENGTH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
21
            throw new \Formularium\Exception\ValidatorException('String is too short.');
22
        }
23
        return $value;
24
    }
25
26
    public function getMetadata(): ValidatorMetadata
27
    {
28
        return new ValidatorMetadata(
29
            __CLASS__,
30
            "Minimum string length",
31
            [
32
                new ValidatorArgs(
0 ignored issues
show
Bug introduced by
The type Formularium\Validator\ValidatorArgs was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
33
                    'value',
34
                    'Integer',
35
                    'Value'
36
                )
37
            ]
38
        );
39
    }
40
}
41