Completed
Pull Request — 3.x (#649)
by
unknown
02:06
created

QueryBuilder::notIn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\DoctrineORMAdminBundle\Tests\Filter;
13
14
use Doctrine\ORM\Query\Expr\Orx;
15
16
class QueryBuilder
17
{
18
    public $parameters = array();
19
20
    public $query = array();
21
22
    /**
23
     * @param string $name
24
     * @param mixed  $value
25
     */
26
    public function setParameter($name, $value)
27
    {
28
        $this->parameters[$name] = $value;
29
    }
30
31
    /**
32
     * @param string $query
33
     */
34
    public function andWhere($query)
35
    {
36
        $this->query[] = $query;
37
    }
38
39
    /**
40
     * @return QueryBuilder
41
     */
42
    public function expr()
43
    {
44
        return $this;
45
    }
46
47
    /**
48
     * @param string $name
49
     * @param string $value
50
     *
51
     * @return string
52
     */
53
    public function in($name, $value)
54
    {
55
        $this->query[] = 'in_'.$name;
56
57
        if (is_array($value)) {
58
            return sprintf('%s IN ("%s")', $name, implode(',', $value));
59
        }
60
61
        return sprintf('%s IN %s', 'in_'.$name, $value);
62
    }
63
64
    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...
65
    {
66
        return array();
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getRootAlias()
73
    {
74
        return 'o';
75
    }
76
77
    /**
78
     * @param string $parameter
79
     * @param string $alias
80
     */
81
    public function leftJoin($parameter, $alias)
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...
82
    {
83
        $this->query[] = $parameter;
84
    }
85
86
    /**
87
     * @return Orx
88
     */
89
    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...
90
    {
91
        return new Orx(func_get_args());
92
    }
93
94
    /**
95
     * @param string $alias
96
     * @param string $parameter
97
     *
98
     * @return string
99
     */
100
    public function neq($alias, $parameter)
101
    {
102
        return sprintf('%s <> %s', $alias, $parameter);
103
    }
104
105
    /**
106
     * @param string $queryPart
107
     *
108
     * @return string
109
     */
110
    public function isNull($queryPart)
111
    {
112
        return $queryPart.' IS NULL';
113
    }
114
115
    /**
116
     * @param string $alias
117
     * @param string $parameter
118
     *
119
     * @return string
120
     */
121
    public function notIn($alias, $parameter)
122
    {
123
        return sprintf('%s NOT IN %s', $alias, $parameter);
124
    }
125
126
    /**
127
     * @return array
128
     */
129
    public function getAllAliases()
130
    {
131
        return array($this->getRootAlias());
132
    }
133
}
134