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

BetweenTester   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B test() 0 11 8
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