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

DateFormat   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 42
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B applyToNode() 0 22 4
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