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

TimezonePipe   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
c 0
b 0
f 0
dl 0
loc 22
rs 10
ccs 0
cts 10
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A pipe() 0 13 3
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