Failed Conditions
Push — master ( 9143b8...91d601 )
by Moesjarraf
02:51
created

DateFormat::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
8
/**
9
 * Transform processor, apply transformation functions on data
10
 */
11
class DateFormat implements Processor
12
{
13
    use Processor\Implementation;
14
    
15
    /**
16
     * Class constructor
17
     * 
18
     * @param string $property  Property key with the processing instruction
19
     */
20
    public function __construct($property)
21
    {
22
        $this->property = $property;
23
    }
24
    
25
    /**
26
     * Apply processing to a single node
27
     * 
28
     * @param Node $node
29
     */
30
    public function applyToNode(Node $node)
31
    {
32
        $instruction = $node->getInstruction($this);
33
        
34
        if(!isset($instruction->date)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
35
            return;
36
        }
37
        
38
        $format = 'Y-m-d';
39
        if (isset($instruction->format)) {
40
            $format = $instruction->format;
41
        }
42
        
43
        $date = new \DateTime($instruction->date);
44
        if (isset($instruction->timezone)) {
45
            $date = new \DateTime($instruction->date, new \DateTimeZone($instruction->timezone));
46
        }
47
        
48
        $result = $date->format($format);
49
        
50
        $node->setResult($result);
51
    }   
52
}
53