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

MinLength::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 MinLength extends AbstractStringRule
6
{
7
    const OPTION_MIN = 'min';
8
    const OPTION_ENCODING = 'encoding';
9
10
    const MESSAGE = 'This input should have at least {min} characters';
11
    const LABELED_MESSAGE = '{label} should have at least {min} characters';
12
13
    protected $options = [];
14
15
    protected $optionsIndexMap = [
16
        0 => self::OPTION_MIN,
17
        1 => self::OPTION_ENCODING
18
    ];
19
20 9
    public function validate($value, string $valueIdentifier = null):bool
21
    {
22 9
        $this->value = $value;
23 9
        if (! isset($this->options['min'])) {
24
            $this->success = true;
25
        } else {
26 9
            $this->success = $this->getStringLength($value) >= $this->options['min'];
27
        }
28
29 9
        return $this->success;
30
    }
31
}
32