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

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