Completed
Push — master ( 675da0...765c9a )
by Changwan
02:43
created

BetweenTester::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Validator\Testers;
3
4
use Wandu\Validator\Contracts\Tester;
5
6
class BetweenTester implements Tester
7
{
8
    /** @var int|string */
9
    protected $min;
10
    
11
    /** @var int|string */
12
    protected $max;
13
14
    /**
15
     * @param int|string $min
16
     * @param int|string $max
17
     */
18 1
    public function __construct($min, $max)
19
    {
20 1
        $this->min = $min;
21 1
        $this->max = $max;
22 1
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 1
    public function test($data, $origin = null, array $keys = []): bool
28
    {
29 1
        if ($data === null) return false;
30 1
        if (is_int($data) || is_float($data)) {
31 1
            return $data <= (int) $this->max && $data >= (int) $this->min;
32
        }
33 1
        if (is_string($data)) {
34 1
            return strcmp($data, $this->min) >= 0 && strcmp($data, $this->max) <= 0;
35
        }
36
        return $data <= $this->max && $data >= $this->min;
37
    }
38
}
39