Completed
Push — master ( d1f538...a2a57f )
by
unknown
02:04 queued 19s
created

QueryBuilder::isNotNull()   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
    public function isNotNull(string $queryPart): string
124
    {
125
        return $queryPart.' IS NOT NULL';
126
    }
127
128
    /**
129
     * @param string $alias
130
     * @param string $parameter
131
     *
132
     * @return string
133
     */
134
    public function notIn($alias, $parameter)
135
    {
136
        return sprintf('%s NOT IN %s', $alias, $parameter);
137
    }
138
139
    /**
140
     * @return array
141
     */
142
    public function getAllAliases()
143
    {
144
        return $this->getRootAliases();
145
    }
146
147
    /**
148
     * @return array
149
     */
150
    public function getRootAliases()
151
    {
152
        return ['o'];
153
    }
154
}
155