Passed
Push — master ( c24a91...e658b6 )
by Peter
02:30
created

MinLength::passes()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Validation\Rules;
6
7
use LogicException;
8
use Opulence\Validation\Rules\MinRule;
9
10
class MinLength extends MinRule
11
{
12
    /**
13
     * @inheritdoc
14
     */
15
    public function getSlug() : string
16
    {
17
        return 'minLength';
18
    }
19
20
    /**
21
     * @inheritdoc
22
     */
23
    public function passes($value, array $allValues = []): bool
24
    {
25
        if ($this->min === null) {
26
            throw new LogicException('Minimum value not set');
27
        }
28
29
        if ($this->isInclusive) {
30
            return mb_strlen($value) >= $this->min;
31
        } else {
32
            return mb_strlen($value) > $this->min;
33
        }
34
    }
35
}
36