DateParam   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 21
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 15 3
1
<?php declare(strict_types=1);
2
3
namespace Bigwhoop\Trumpet\Config\Params;
4
5
use Bigwhoop\Trumpet\Config\ConfigException;
6
use Bigwhoop\Trumpet\Config\Presentation;
7
use Bigwhoop\Trumpet\Config\Date;
8
9
final class DateParam implements Param
10
{
11
    /**
12
     * {@inheritdoc}
13
     */
14 7
    public function parse($value, Presentation $presentation)
15
    {
16 7
        if (is_int($value)) {
17
            // We don't use format 'U' as the TZ would be UTC
18 1
            $date = \DateTime::createFromFormat('Y-m-d', date('Y-m-d', $value));
19 6
        } elseif (preg_match('#\d{4}-\d{1,2}-\d{1,2}#', $value)) {
20 1
            $date = \DateTime::createFromFormat('Y-m-d', $value);
21
        } else {
22 5
            throw new ConfigException('Dates must be a string in the format YYYY-MM-DD.');
23
        }
24
25 2
        $date->setTime(0, 0, 0);
26
27 2
        $presentation->date = new Date($date);
0 ignored issues
show
Security Bug introduced by
It seems like $date can also be of type false; however, Bigwhoop\Trumpet\Config\Date::__construct() does only seem to accept object<DateTime>, did you maybe forget to handle an error condition?
Loading history...
28 2
    }
29
}
30