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

MaxLength   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 10 3
A getMetadata() 0 10 1
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 MaxLength implements ValidatorInterface
12
{
13
    public function validate($value, array $options = [], Model $model = null)
14
    {
15
        if (!is_string($value)) {
16
            throw new ValidatorException('Expected a string.');
17
        }
18
        $maxlength = $options['value'];
19
        if (mb_strlen($text) > $maxlength) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $text seems to be never defined.
Loading history...
20
            throw new ValidatorException('String is too long.');
21
        }
22
        return $value;
23
    }
24
25
    public function getMetadata(): ValidatorMetadata
26
    {
27
        return new ValidatorMetadata(
28
            __CLASS__,
29
            "Maximum string length",
30
            [
31
                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...
32
                    'value',
33
                    'Integer',
34
                    'Value'
35
                )
36
            ]
37
        );
38
    }
39
}
40