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

SolariumVisitor::visitScalar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 3
1
<?php
2
3
namespace RulerZ\Target\Solarium;
4
5
use Hoa\Ruler\Model as AST;
6
7
use RulerZ\Model;
8
use RulerZ\Target\GenericVisitor;
9
10
class SolariumVisitor extends GenericVisitor
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15
    public function visitModel(AST\Model $element, &$handle = null, $eldnah = null)
16
    {
17
        $searchQuery = parent::visitModel($element, $handle, $eldnah);
18
19
        return "'" . $searchQuery . "'";
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null)
26
    {
27
        return $element->getId();
28
    }
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function visitScalar(AST\Bag\Scalar $element, &$handle = null, $eldnah = null)
34
    {
35
        $value = $element->getValue();
36
37
        return is_numeric($value) ? $value : sprintf('"%s"', $value);
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function visitParameter(Model\Parameter $element, &$handle = null, $eldnah = null)
44
    {
45
        // FIXME the parameters handling is REALLY hacky
46
        $parameterName = $element->getName();
47
48
        return "'. \$parameters['$parameterName'] .'";
49
    }
50
}
51