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

NativeVisitor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A visitAccess() 0 12 2
A visitParameter() 0 4 1
A visitArray() 0 4 1
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