Completed
Push — master ( f5c89e...6e16e6 )
by Adrian
02:13
created

MaxLength   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 27
ccs 5
cts 6
cp 0.8333
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 11 2
1
<?php
2
declare(strict_types=1);
3
namespace Sirius\Validation\Rule;
4
5
class MaxLength extends AbstractStringRule
6
{
7
    const OPTION_MAX = 'max';
8
    const OPTION_ENCODING = 'encoding';
9
10
    const MESSAGE = 'This input should have less than {max} characters';
11
    const LABELED_MESSAGE = '{label} should have less than {max} characters';
12
13
    protected $options = [];
14
15
    protected $optionsIndexMap = [
16
        0 => self::OPTION_MAX,
17
        1 => self::OPTION_ENCODING
18
    ];
19
20 2
    public function validate($value, string $valueIdentifier = null):bool
21
    {
22 2
        $this->value = $value;
23 2
        if (! isset($this->options['max'])) {
24
            $this->success = true;
25
        } else {
26 2
            $this->success = $this->getStringLength($value) <= $this->options['max'];
27
        }
28
29 2
        return $this->success;
30
    }
31
}
32