BetweenRule   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 6 4
A canSkip() 0 3 1
A errorMessage() 0 3 1
1
<?php
2
3
4
namespace SolBianca\Validator\Rules;
5
6
7
use SolBianca\Validator\Interfaces\RuleInterface;
8
9
class BetweenRule implements RuleInterface
10
{
11
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function run($value, array $input, array $args): bool
16
    {
17
        if (!is_numeric($value)) {
18
            return false;
19
        }
20
        return ($value >= $args[0] && $value <= $args[1]) ? true : false;
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function errorMessage(): string
27
    {
28
        return 'Field `{field}` must be between `{$0}` and `{$1}``.';
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function canSkip(): bool
35
    {
36
        return true;
37
    }
38
}