Completed
Push — master ( ac62eb...633109 )
by Dawid
03:39
created

Date::getExtractor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Igni\Storage\Mapping\Strategy;
4
5
use Igni\Storage\Mapping\MappingStrategy;
6
7
final class Date implements MappingStrategy, DefaultAttributesProvider
8
{
9 6
    public static function hydrate(&$value, array $attributes = []): void
10
    {
11 6
        if ($value !== null) {
12 2
            $value = new \DateTime($value, new \DateTimeZone($attributes['timezone']));
13
        }
14 6
    }
15
16 3
    public static function extract(&$value, array $attributes = []): void
17
    {
18 3
        if ($value instanceof \DateTimeInterface) {
19 1
            $value = $value->format($attributes['format']);
20
        } else {
21 2
            $value = null;
22
        }
23 3
    }
24
25 5
    public static function getDefaultAttributes(): array
26
    {
27
        return [
28 5
            'timezone' => 'UTC',
29
            'format' => 'Ymd',
30
        ];
31
    }
32
}
33