Test Failed
Push — master ( c71310...b1cf76 )
by Julien
20:09
created

QueryBuilder::distinct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of the Zemit Framework.
5
 *
6
 * (c) Zemit Team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE.txt
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zemit\Mvc\Model\EagerLoading;
13
14
use Phalcon\Mvc\Model\Query\Builder;
15
use Phalcon\Mvc\Model\Query\BuilderInterface;
16
17
final class QueryBuilder extends Builder
18
{
19
    public const string E_NOT_ALLOWED_METHOD_CALL = 'When eager loading relations queries must return full entities';
20
    
21
    /**
22
     * @param mixed $distinct
23
     * @return BuilderInterface
24
     * @throws \LogicException
25
     */
26
    public function distinct($distinct): BuilderInterface
27
    {
28
        throw new \LogicException(self::E_NOT_ALLOWED_METHOD_CALL);
29
    }
30
    
31
    /**
32
     * @param mixed $columns
33
     * @return BuilderInterface
34
     * @throws \LogicException
35
     */
36
    public function columns($columns): BuilderInterface
37
    {
38
        throw new \LogicException(self::E_NOT_ALLOWED_METHOD_CALL);
39
    }
40
    
41
    /**
42
     * Replacing where to andWhere in order to avoid loosing relationship conditions
43
     */
44
    public function where(string $conditions, array $bindParams = [], array $bindTypes = []): BuilderInterface
45
    {
46
        if (!empty($this->conditions)) {
47
            $appendCondition = is_array($this->conditions)? implode(') AND (', $this->conditions) : $this->conditions;
48
            $conditions = '(' . $appendCondition . ') AND (' . $conditions . ')';
49
        }
50
        return parent::where($conditions, $bindParams, $bindTypes);
51
    }
52
}
53