GreaterThanOrEqualTo   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 25
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A message() 0 3 1
A validate() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MiladRahimi\Jwt\Validator\Rules;
6
7
use MiladRahimi\Jwt\Exceptions\ValidationException;
8
use MiladRahimi\Jwt\Validator\Rule;
9
10
/**
11
 * It checks if the claim is greater than or equal the given number
12
 */
13
class GreaterThanOrEqualTo implements Rule
14
{
15
    protected float $number;
16
17
    public function __construct(float $number)
18
    {
19
        $this->number = $number;
20
    }
21
22
    /**
23
     * @inheritdoc
24
     */
25
    public function validate(string $name, $value)
26
    {
27
        if ($value < $this->number) {
28
            throw new ValidationException($this->message($name));
29
        }
30
    }
31
32
    /**
33
     * Generate error message
34
     */
35
    protected function message(string $name): string
36
    {
37
        return "The `$name` must be greater than or equal to `$this->number`.";
38
    }
39
}
40