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

MaxLength::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0185
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