Completed
Push — master ( 68be21...073c54 )
by Kévin
02:41
created

NativeVisitor::visitAccess()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 6
nc 2
nop 3
1
<?php
2
3
namespace RulerZ\Target\Native;
4
5
use Hoa\Ruler\Model as AST;
6
7
use RulerZ\Model;
8
use RulerZ\Target\GenericVisitor;
9
10
class NativeVisitor extends GenericVisitor
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15
    public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null)
16
    {
17
        $flattenedDimensions = [
18
            sprintf('["%s"]', $element->getId())
19
        ];
20
21
        foreach ($element->getDimensions() as $dimension) {
22
            $flattenedDimensions[] = sprintf('["%s"]', $dimension[AST\Bag\Context::ACCESS_VALUE]);
23
        }
24
25
        return '$target' . implode('', $flattenedDimensions);
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function visitParameter(Model\Parameter $element, &$handle = null, $eldnah = null)
32
    {
33
        return sprintf('$parameters["%s"]', $element->getName());
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39
    public function visitArray(AST\Bag\RulerArray $element, &$handle = null, $eldnah = null)
40
    {
41
        return sprintf('array(%s)', implode(', ', parent::visitArray($element, $handle, $eldnah)));
42
    }
43
}
44