DateTimeProcessor   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A hydrate() 0 6 2
A dehydrate() 0 4 1
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the KleijnWeb\PhpApi\Hydrator package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\PhpApi\Hydrator\Processors\Scalar;
10
11
use KleijnWeb\PhpApi\Descriptions\Description\Schema\ScalarSchema;
12
use KleijnWeb\PhpApi\Hydrator\DateTimeSerializer;
13
14
/**
15
 * @author John Kleijn <[email protected]>
16
 */
17
class DateTimeProcessor extends ScalarProcessor
18
{
19
    /**
20
     * @var DateTimeSerializer
21
     */
22
    protected $dateTimeSerializer;
23
24
25
    public function __construct(ScalarSchema $schema, DateTimeSerializer $dateTimeSerializer)
26
    {
27
        parent::__construct($schema);
28
        $this->dateTimeSerializer = $dateTimeSerializer;
29
    }
30
31
    /**
32
     * @param string $value
33
     * @return \DateTime
34
     */
35
    public function hydrate($value)
36
    {
37
        $value = $value === null ? $this->schema->getDefault() : $value;
38
39
        return $this->dateTimeSerializer->deserialize($value, $this->schema);
40
    }
41
42
    /**
43
     * @param mixed $value
44
     * @return string
45
     */
46
    public function dehydrate($value)
47
    {
48
        return $this->dateTimeSerializer->serialize($value, $this->schema);
49
    }
50
}
51