Completed
Pull Request — 3.x (#999)
by
unknown
01:28
created

QueryBuilder::andX()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[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 Sonata\DoctrineORMAdminBundle\Tests\Filter;
15
16
use Doctrine\ORM\Query\Expr\Andx;
17
use Doctrine\ORM\Query\Expr\Orx;
18
19
class QueryBuilder
20
{
21
    public $parameters = [];
22
23
    public $query = [];
24
25
    /**
26
     * @param string $name
27
     * @param mixed  $value
28
     */
29
    public function setParameter($name, $value): void
30
    {
31
        $this->parameters[$name] = $value;
32
    }
33
34
    /**
35
     * @param string $query
36
     */
37
    public function andWhere($query): void
38
    {
39
        $this->query[] = $query;
40
    }
41
42
    /**
43
     * @return QueryBuilder
44
     */
45
    public function expr()
46
    {
47
        return $this;
48
    }
49
50
    /**
51
     * @param string $name
52
     * @param string $value
53
     *
54
     * @return string
55
     */
56
    public function in($name, $value)
57
    {
58
        $this->query[] = 'in_'.$name;
59
60
        if (\is_array($value)) {
61
            return sprintf('%s IN ("%s")', $name, implode(',', $value));
62
        }
63
64
        return sprintf('%s IN %s', 'in_'.$name, $value);
65
    }
66
67
    public function getDQLPart($queryPart)
0 ignored issues
show
Unused Code introduced by
The parameter $queryPart is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
68
    {
69
        return [];
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getRootAlias()
76
    {
77
        return current(($this->getRootAliases()));
78
    }
79
80
    /**
81
     * @param string $parameter
82
     * @param string $alias
83
     */
84
    public function leftJoin($parameter, $alias): void
0 ignored issues
show
Unused Code introduced by
The parameter $alias is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        $this->query[] = $parameter;
87
    }
88
89
    /**
90
     * @return Orx
91
     */
92
    public function orX($x = null)
0 ignored issues
show
Unused Code introduced by
The parameter $x is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
93
    {
94
        return new Orx(\func_get_args());
95
    }
96
97
    public function andX($x = null): Andx
0 ignored issues
show
Unused Code introduced by
The parameter $x is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
    {
99
        return new Andx(\func_get_args());
100
    }
101
102
    /**
103
     * @param string $alias
104
     * @param string $parameter
105
     *
106
     * @return string
107
     */
108
    public function neq($alias, $parameter)
109
    {
110
        return sprintf('%s <> %s', $alias, $parameter);
111
    }
112
113
    /**
114
     * @param string $queryPart
115
     *
116
     * @return string
117
     */
118
    public function isNull($queryPart)
119
    {
120
        return $queryPart.' IS NULL';
121
    }
122
123
    /**
124
     * @param string $queryPart
125
     */
126
    public function isNotNull($queryPart): string
127
    {
128
        return $queryPart.' IS NOT NULL';
129
    }
130
131
    /**
132
     * @param string $alias
133
     * @param string $parameter
134
     *
135
     * @return string
136
     */
137
    public function notIn($alias, $parameter)
138
    {
139
        return sprintf('%s NOT IN %s', $alias, $parameter);
140
    }
141
142
    /**
143
     * @return array
144
     */
145
    public function getAllAliases()
146
    {
147
        return $this->getRootAliases();
148
    }
149
150
    /**
151
     * @return array
152
     */
153
    public function getRootAliases()
154
    {
155
        return ['o'];
156
    }
157
}
158