Before   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 18 4
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 Exception;
15
use Rakit\Validation\Rules\Traits\DateUtilsTrait;
16
17
class Before extends AbstractRule
18
{
19
    use DateUtilsTrait;
20
21
    /**
22
     * @var array
23
     */
24
    protected $fillableParams = ['time'];
25
26
    /**
27
     * Check the value is valid
28
     *
29
     * @param mixed $value
30
     *
31
     * @throws Exception
32
     */
33
    public function check($value): bool
34
    {
35 2
        $this->requireParameters($this->fillableParams);
36 2
        $time = $this->parameter('time');
37
38
        if (! $this->isValidDate($value)) {
39 2
            throw $this->throwException($value);
40
        }
41
42
        if (! $this->isValidDate($time)) {
43 2
            $time = $this->getAttribute()->getValue($time);
44
        }
45
46
        if (! $this->isValidDate($time)) {
47 2
            throw $this->throwException($time);
48
        }
49
50 2
        return $this->getTimeStamp($time) > $this->getTimeStamp($value);
51
    }
52
}
53