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

MinLength   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 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