DateTimeToIso8601Transformer::transform()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 3
1
<?php
2
3
namespace TreeHouse\Feeder\Modifier\Data\Transformer;
4
5
use TreeHouse\Feeder\Exception\TransformationFailedException;
6
7
class DateTimeToIso8601Transformer implements TransformerInterface
8
{
9
    /**
10
     * @inheritdoc
11
     */
12 10
    public function transform($value)
13
    {
14 10
        if (is_null($value)) {
15 2
            return null;
16
        }
17
18 8
        if (!$value instanceof \DateTime) {
19 6
            throw new TransformationFailedException(
20 6
                sprintf('Expected a DateTime to transform, got "%s" instead.', json_encode($value))
21 6
            );
22
        }
23
24 2
        return $value->format(DATE_ISO8601);
25
    }
26
}
27