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

DoctrineORMVisitor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 5
c 4
b 1
f 0
lcom 1
cbo 3
dl 0
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCompilationData() 0 6 1
A visitAccess() 0 4 1
A visitParameter() 0 10 2
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