Field   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A transform() 0 8 2
1
<?php
2
3
/**
4
 * This file is part of the Happyr Doctrine Specification package.
5
 *
6
 * (c) Tobias Nyholm <[email protected]>
7
 *     Kacper Gunia <[email protected]>
8
 *     Peter Gribanov <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Happyr\DoctrineSpecification\Operand;
15
16
use Doctrine\ORM\QueryBuilder;
17
use Happyr\DoctrineSpecification\Query\Selection\Selection;
18
19
class Field implements Operand, Selection
20
{
21
    /**
22
     * @var string
23
     */
24
    private $fieldName;
25
26
    /**
27
     * @var string|null
28
     */
29
    private $dqlAlias;
30
31
    /**
32
     * @param string      $fieldName
33
     * @param string|null $dqlAlias
34
     */
35
    public function __construct($fieldName, $dqlAlias = null)
36
    {
37
        $this->fieldName = $fieldName;
38
        $this->dqlAlias = $dqlAlias;
39
    }
40
41
    /**
42
     * @param QueryBuilder $qb
43
     * @param string       $dqlAlias
44
     *
45
     * @return string
46
     */
47
    public function transform(QueryBuilder $qb, $dqlAlias)
48
    {
49
        if (null !== $this->dqlAlias) {
50
            $dqlAlias = $this->dqlAlias;
51
        }
52
53
        return sprintf('%s.%s', $dqlAlias, $this->fieldName);
54
    }
55
}
56