Passed
Push — master ( d1ed92...06623e )
by Lukas
02:23
created

TimezonePipe::pipe()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 13
rs 10
ccs 0
cts 10
cp 0
cc 3
nc 3
nop 4
crap 12
1
<?php
2
3
namespace Lneicelis\Transformer\Pipe;
4
5
use DateTime;
6
use Lneicelis\Transformer\Contract\CanPipe;
7
use Lneicelis\Transformer\Contract\HasTimezone;
8
use Lneicelis\Transformer\ValueObject\Context;
9
use Lneicelis\Transformer\ValueObject\Path;
10
11
class TimezonePipe implements CanPipe
12
{
13
    /**
14
     * @param object $resource
15
     * @param Context $context
16
     * @param Path $path
17
     * @param $data
18
     * @return mixed
19
     */
20
    public function pipe($resource, Context $context, Path $path, $data)
21
    {
22
        if (! $context instanceof HasTimezone) {
23
            return $data;
24
        }
25
26
        if (! $resource instanceof DateTime) {
27
            return $data;
28
        }
29
30
        $resource->setTimezone($context->getTimezone());
31
32
        return $data;
33
    }
34
}
35