NodeTranslation::inLoop()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
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\Dom\Element;
14
15
/**
16
 *
17
 */
18
class NodeTranslation extends AbstractPlugin implements InLoopPluginInterface
19
{
20
    /**
21
     * @var array
22
     */
23
    protected $lastNodeTranslation = [];
24
25
    /**
26
     * @param PluginArgument $arg
27
     */
28
    public function inLoop(PluginArgument $arg)
29
    {
30
        $node = $arg->getNode();
31
        if (!$node instanceof Element) {
32
            return;
33
        }
34
35
        $translation = $arg->getTranslation();
36
        // unset the last node translation then merge current one
37
        $nodeTranslation = $this->createNodeTranslation($node, $arg->getSpec());
38
        $translation->unsetKeys(array_keys($this->lastNodeTranslation));
39
        $this->lastNodeTranslation = $nodeTranslation->getArrayCopy();
40
        $translation->merge($this->lastNodeTranslation);
41
    }
42
}
43