Failed Conditions
Push — master ( da580a...04820f )
by Moesjarraf
03:10
created

DateFormat::applyToNode()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 8.9197
cc 4
eloc 12
nc 5
nop 1
crap 4
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 5
    public function applyToNode(Node $node)
21
    {
22 5
        $instruction = $node->getInstruction($this);
23
        
24 5
        if(!isset($instruction->date)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
25 1
            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