DateFormat   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B applyToNode() 0 23 6
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 6
    public function applyToNode(Node $node)
21
    {
22 6
        $instruction = $node->getInstruction($this);
23
        
24 6
        if(!isset($instruction->date) && !isset($instruction->input)) {
25 1
            return;
26
        }
27
        
28 5
        $format = 'Y-m-d';
29 5
        if (isset($instruction->format)) {
30 5
            $format = $instruction->format;
31 5
        }
32
        
33 5
        $input = isset($instruction->input) ? $instruction->input : $instruction->date;
34 5
        $date = new \DateTime($input);
35 5
        if (isset($instruction->timezone)) {
36 1
            $date = new \DateTime($input, new \DateTimeZone($instruction->timezone));
37 1
        }
38
        
39 5
        $result = $date->format($format);
40
        
41 5
        $node->setResult($result);
42 5
    }   
43
}
44