DateEquals::check()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 18
ccs 6
cts 6
cp 1
crap 4
rs 9.9666
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 Rakit\Validation\Rules\Traits\DateUtilsTrait;
15
16
class DateEquals extends AbstractRule
17
{
18
    use DateUtilsTrait;
19
20
    /**
21
     * @var array
22
     */
23
    protected $fillableParams = ['date'];
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    public function check($value): bool
29
    {
30 2
        $this->requireParameters($this->fillableParams);
31 2
        $time = $this->parameter('date');
32
33
        if (! $this->isValidDate($value)) {
34 2
            throw $this->throwException($value);
35
        }
36
37
        if (! $this->isValidDate($time)) {
38 2
            $time = $this->getAttribute()->getValue($time);
39
        }
40
41
        if (! $this->isValidDate($time)) {
42 2
            throw $this->throwException($time);
43
        }
44
45 2
        return $this->getTimeStamp($time) === $this->getTimeStamp($value);
46
    }
47
}
48