IsDate::validate()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 12
rs 10
1
<?php
2
3
namespace kalanis\kw_rules\Rules\External;
4
5
6
use kalanis\kw_rules\Interfaces\IValidate;
7
use kalanis\kw_rules\Exceptions\RuleException;
8
use kalanis\kw_rules\Rules\ARule;
9
10
11
/**
12
 * Class IsDate
13
 * @package kalanis\kw_rules\Rules\External
14
 * Check if input is date for preset format
15
 * @link http://schoolsofweb.com/how-to-check-valid-date-format-in-php/
16
 * Beware! It depends on PHP's parsing! Better use something else.
17
 * @codeCoverageIgnore when I wrote tests I have zero will for defining all available date formats
18
 */
19
class IsDate extends ARule
20
{
21
    public function validate(IValidate $entry): void
22
    {
23
        $dtInfo = date_parse($entry->getValue());
24
        if (0 == $dtInfo['warning_count'] && 0 == $dtInfo['error_count']) {
25
            return;
26
        }
27
        throw new RuleException($this->errorText);
28
    }
29
}
30