QueryBuilder::in()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
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|Orx|Andx $query
36
     */
37
    public function andWhere($query): void
38
    {
39
        $this->query[] = (string) $query;
40
    }
41
42
    /**
43
     * @return QueryBuilder
44
     */
45
    public function expr()
46
    {
47
        return $this;
48
    }
49
50
    /**
51
     * @param string          $alias
52
     * @param string|string[] $parameter
53
     *
54
     * @return string
55
     */
56
    public function in($alias, $parameter)
57
    {
58
        if (\is_array($parameter)) {
59
            return sprintf('%s IN ("%s")', $alias, implode(', ', $parameter));
60
        }
61
62
        return sprintf('%s IN %s', $alias, $parameter);
63
    }
64
65
    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...
66
    {
67
        return [];
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getRootAlias()
74
    {
75
        return current(($this->getRootAliases()));
76
    }
77
78
    /**
79
     * @param string $parameter
80
     * @param string $alias
81
     */
82
    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...
83
    {
84
        $this->query[] = $parameter;
85
    }
86
87
    /**
88
     * @return Orx
89
     */
90
    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...
91
    {
92
        return new Orx(\func_get_args());
93
    }
94
95
    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...
96
    {
97
        return new Andx(\func_get_args());
98
    }
99
100
    /**
101
     * @param string $alias
102
     * @param string $parameter
103
     *
104
     * @return string
105
     */
106
    public function neq($alias, $parameter)
107
    {
108
        return sprintf('%s <> %s', $alias, $parameter);
109
    }
110
111
    /**
112
     * @param string $queryPart
113
     *
114
     * @return string
115
     */
116
    public function isNull($queryPart)
117
    {
118
        return $queryPart.' IS NULL';
119
    }
120
121
    public function isNotNull(string $queryPart): string
122
    {
123
        return $queryPart.' IS NOT NULL';
124
    }
125
126
    /**
127
     * @param string          $alias
128
     * @param string|string[] $parameter
129
     *
130
     * @return string
131
     */
132
    public function notIn($alias, $parameter)
133
    {
134
        if (\is_array($parameter)) {
135
            return sprintf('%s NOT IN ("%s")', $alias, implode(', ', $parameter));
136
        }
137
138
        return sprintf('%s NOT IN %s', $alias, $parameter);
139
    }
140
141
    /**
142
     * @return array
143
     */
144
    public function getAllAliases()
145
    {
146
        return $this->getRootAliases();
147
    }
148
149
    /**
150
     * @return array
151
     */
152
    public function getRootAliases()
153
    {
154
        return ['o'];
155
    }
156
}
157