Date   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 6 2
1
<?php
2
3
namespace Mbright\Validation\Rule\Validate\MySql;
4
5
use Mbright\Validation\Rule\Validate\ValidateRuleInterface;
6
7
/**
8
 * Validates that data can be inserted into one of the following column types:
9
 * - Date
10
 */
11
class Date implements ValidateRuleInterface
12
{
13
    use DateTypeTrait;
14
15
    protected $delimiterPattern = '[^[:punct:]]';
16
17
    /**
18
     * Returns a bool indicating if the value can be safely stored in a MySql Date column.
19
     *
20
     * @param object $subject
21
     * @param string $field
22
     *
23
     * @return bool
24
     */
25 36
    public function __invoke($subject, string $field): bool
26
    {
27 36
        $value = (string) $subject->$field;
28 36
        $dateParts = $this->extractDateParts($value, $this->delimiterPattern, true);
29
30 36
        return !is_null($dateParts) && checkdate($dateParts->month, $dateParts->day, $dateParts->year);
31
    }
32
}
33