Completed
Push — master ( 073c54...10f0f3 )
by Kévin
02:32
created

DoctrineORMVisitor::getRootAlias()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace RulerZ\Target\DoctrineORM;
4
5
use Hoa\Ruler\Model as AST;
6
7
use RulerZ\Compiler\Context;
8
use RulerZ\Exception;
9
use RulerZ\Model;
10
use RulerZ\Target\GenericSqlVisitor;
11
use RulerZ\Target\Operators\Definitions as OperatorsDefinitions;
12
13
class DoctrineORMVisitor extends GenericSqlVisitor
14
{
15
    /**
16
     * @var DoctrineAutoJoin
17
     */
18
    private $autoJoin;
19
20
    public function __construct(Context $context, OperatorsDefinitions $operators, $allowStarOperator = true)
21
    {
22
        parent::__construct($context, $operators, $allowStarOperator);
23
24
        $this->autoJoin = new DoctrineAutoJoin($context['em'], $context['root_entities'], $context['root_aliases'], $context['joins']);
25
    }
26
27
    /**
28
     * @inheritDoc
29
     */
30
    public function getCompilationData()
31
    {
32
        return [
33
            'detectedJoins' => $this->autoJoin->getDetectedJoins(),
34
        ];
35
    }
36
37
    /**
38
     * {@inheritDoc}
39
     */
40
    public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null)
41
    {
42
        return $this->autoJoin->buildAccessPath($element);
43
    }
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    public function visitParameter(Model\Parameter $element, &$handle = null, $eldnah = null)
49
    {
50
        // placeholder for a positional parameters
51
        if (is_int($element->getName())) {
52
            return '?' . $element->getName();
53
        }
54
55
        // placeholder for a named parameter
56
        return ':' . $element->getName();
57
    }
58
}
59