Completed
Push — master ( 0915e8...0e3c40 )
by Albert
02:09
created

Length::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Albert221\Validation\Rule;
4
5
class Length implements RuleInterface
6
{
7
    use RuleTrait;
8
9
    protected $length;
10
11 4
    public function __construct($length)
12
    {
13 4
        $this->message = 'This field is not the proper length.';
14
15 4
        if (! is_int($length)) {
16 1
            throw new \InvalidArgumentException(
17 1
                sprintf('Minimum length must be type of int, %s given.', gettype($length))
18 1
            );
19
        }
20
21 3
        $this->length = $length;
22 3
    }
23
24 3
    public function test($value)
25
    {
26 3
        return mb_strlen($value) == $this->length;
27
    }
28
}
29