Failed Conditions
Push — master ( e245a2...503ac3 )
by Arnold
8s
created

Mustache   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A applyToNode() 0 7 1
A parse() 0 7 1
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher\Node;
6
use LegalThings\DataEnricher\Processor;
7
use LegalThings\DataEnricher\Processor\Helper;
8
use Mustache_Engine;
9
10
/**
11
 * Process string as Mustache template
12
 */
13
class Mustache implements Processor
14
{
15
    use Processor\Implementation,
16
        Helper\GetByReference
17
    {
18
        Helper\GetByReference::withSourceAndTarget insteadof Processor\Implementation;
19
    }
20
21
    /**
22
     * Apply processing to a single node
23
     * 
24
     * @param Node $node
25
     */
26
    public function applyToNode(Node $node)
27
    {
28
        $template = $node->getInstruction($this);
29
        $result = $this->parse($template);
30
        
31
        $node->setResult($result);
32
    }
33
    
34
    /**
35
     * Parse as mustache template
36
     * 
37
     * @param string $template
38
     */
39
    protected function parse($template)
40
    {
41
        $data = get_object_vars($this->source) + ['@' => $this->target];
42
        
43
        $mustache = new Mustache_Engine();
44
        return $mustache->render($template, $data);
45
    }
46
}
47