Passed
Push — main ( 4df161...926316 )
by Dimitri
03:36
created

Between   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
ccs 6
cts 6
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 13 3
1
<?php
2
3
/**
4
 * This file is part of Dimtrovich/Validation.
5
 *
6
 * (c) 2023 Dimitri Sitchet Tomkeu <[email protected]>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Dimtrovich\Validation\Rules;
13
14
use Dimtrovich\Validation\Traits\SizeTrait;
15
16
class Between extends AbstractRule
17
{
18
    use SizeTrait;
19
20
    /**
21
     * @var array
22
     */
23
    protected $fillableParams = ['min', 'max'];
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    public function check($value): bool
29
    {
30 4
        $this->requireParameters($this->fillableParams);
31
32 4
        $min       = $this->getBytesSize($this->parameter('min'));
33 4
        $max       = $this->getBytesSize($this->parameter('max'));
34 4
        $valueSize = $this->getValueSize($value);
35
36
        if (! is_numeric($valueSize)) {
37 2
            return false;
38
        }
39
40 4
        return $valueSize >= $min && $valueSize <= $max;
41
    }
42
}
43