Between   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 8 3
A __construct() 0 4 1
1
<?php
2
3
namespace Mbright\Validation\Rule\Validate;
4
5
class Between implements ValidateRuleInterface
6
{
7
    /** @var int */
8
    protected $min;
9
    
10
    /** @var int */
11
    protected $max;
12
13
    /**
14
     * @param int $min minimum 'floor' value
15
     * @param int $max maximum 'ceiling' value
16
     */
17 27
    public function __construct(int $min, int $max)
18
    {
19 27
        $this->min = $min;
20 27
        $this->max = $max;
21 27
    }
22
23
    /**
24
     * Validates that a field's value is between the given min and max.
25
     *
26
     * @param $subject
27
     * @param string $field
28
     *
29
     * @return bool
30
     */
31 27
    public function __invoke($subject, string $field): bool
32
    {
33 27
        $value = $subject->$field;
34 27
        if (!is_scalar($value)) {
35 3
            return false;
36
        }
37
38 24
        return ($value >= $this->min && $value <= $this->max);
39
    }
40
}
41