OnVar   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 48
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A inLoop() 0 22 2
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDraw for the canonical source repository
6
 * @copyright   Copyright (c) 2012-2017 Webino, s. r. o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoDraw\Manipulator\Plugin;
12
13
use WebinoDraw\Instructions\InstructionsRenderer;
14
use WebinoDraw\VarTranslator\VarTranslator;
15
16
/**
17
 *
18
 */
19
class OnVar implements InLoopPluginInterface
20
{
21
    /**
22
     * @var VarTranslator
23
     */
24
    protected $varTranslator;
25
26
    /**
27
     * @var InstructionsRenderer
28
     */
29
    protected $instructionsRenderer;
30
31
    /**
32
     * @param VarTranslator $varTranslator
33
     * @param InstructionsRenderer $instructionsRenderer
34
     */
35
    public function __construct(VarTranslator $varTranslator, InstructionsRenderer $instructionsRenderer)
36
    {
37
        $this->varTranslator        = $varTranslator;
38
        $this->instructionsRenderer = $instructionsRenderer;
39
    }
40
41
    /**
42
     * @param PluginArgument $arg
43
     */
44
    public function inLoop(PluginArgument $arg)
45
    {
46
        $spec = $arg->getSpec();
47
        if (empty($spec['onVar'])) {
48
            return;
49
        }
50
51
        $this->varTranslator->applyOnVar(
52
            $arg->getVarTranslation(),
53
            $spec['onVar'],
54
            function (array $spec) use ($arg) {
55
56
                $this->instructionsRenderer
57
                    ->expandInstructions($spec, $arg->getTranslation())
58
                    ->subInstructions(
59
                        $arg->getNodes(),
60
                        $spec['instructions'],
61
                        $arg->getTranslation()
62
                    );
63
            }
64
        );
65
    }
66
}
67