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

DateFormat   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 32
ccs 15
cts 15
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
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
 * 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