Completed
Push — master ( 91d601...da580a )
by Moesjarraf
04:29
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
 * DateFormat processor, format date objects
10
 */
11
class DateFormat implements Processor
12
{
13
    use Processor\Implementation;
14
    
15
    /**
16
     * Apply processing to a single node
17
     * 
18
     * @param Node $node
19
     */
20 4
    public function applyToNode(Node $node)
21
    {
22 4
        $instruction = $node->getInstruction($this);
23
        
24 4
        if(!isset($instruction->date)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
25
            return;
26
        }
27
        
28 4
        $format = 'Y-m-d';
29 4
        if (isset($instruction->format)) {
30 4
            $format = $instruction->format;
31 4
        }
32
        
33 4
        $date = new \DateTime($instruction->date);
34 4
        if (isset($instruction->timezone)) {
35 1
            $date = new \DateTime($instruction->date, new \DateTimeZone($instruction->timezone));
36 1
        }
37
        
38 4
        $result = $date->format($format);
39
        
40 4
        $node->setResult($result);
41 4
    }   
42
}
43