Completed
Pull Request — master (#5)
by Moesjarraf
09:47
created

Mustache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A applyToNode() 0 7 1
A parse() 0 5 1
1
<?php
2
3
namespace LegalThings\DataEnricher\Processor;
4
5
use LegalThings\DataEnricher;
6
use LegalThings\DataEnricher\Node;
7
use LegalThings\DataEnricher\Processor;
8
use Mustache_Engine;
9
10
/**
11
 * Process string as Mustache template
12
 */
13
class Mustache implements Processor
14
{
15
    use Processor\Implementation;
16
    
17
    /**
18
     * @var object
19
     */
20
    protected $source;
21
    
22
    /**
23
     * Class constructor
24
     * 
25
     * @param DataEnricher $invoker
26
     * @param string       $property  Property key which should trigger the processor
27
     */
28
    public function __construct(DataEnricher $invoker, $property)
29
    {
30
        $this->source = $invoker->getSource();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
31
        $this->property = $property;
32
    }
33
34
    /**
35
     * Apply processing to a single node
36
     * 
37
     * @param Node $node
38
     */
39
    protected function applyToNode(Node $node)
40
    {
41
        $template = $node->getInstruction($this);
42
        $result = $this->parse($template);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
43
        
44
        $node->setResult($result);
45
    }
46
    
47
    /**
48
     * Parse as mustache template
49
     * 
50
     * @param string $template
51
     */
52
    protected function parse($template)
53
    {
54
        $mustache = new Mustache_Engine();
55
        return $mustache->render($template, $this->source);
56
    }
57
}
58