Completed
Push — master ( 74c3c7...591b88 )
by Eric
08:09
created

ExpressionBuilder::isNotNull()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Component\Grid\DataSource\Doctrine\MongoDB;
13
14
use Doctrine\ODM\MongoDB\Query\Builder;
15
use Doctrine\ODM\MongoDB\Query\Expr;
16
use Lug\Component\Grid\DataSource\ExpressionBuilderInterface;
17
18
/**
19
 * @author GeLo <[email protected]>
20
 */
21
class ExpressionBuilder implements ExpressionBuilderInterface
22
{
23
    /**
24
     * @var Builder
25
     */
26
    private $queryBuilder;
27
28
    /**
29
     * @param Builder $queryBuilder
30
     */
31 27
    public function __construct(Builder $queryBuilder)
32
    {
33 27
        $this->queryBuilder = $queryBuilder;
34 27
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 2
    public function andX(array $expressions)
40
    {
41 2
        $expr = $this->expr();
42
43 2
        foreach ($expressions as $expression) {
44 2
            $expr->addAnd($expression);
45 2
        }
46
47 2
        return $expr;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $expr; (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...nBuilderInterface::andX of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53 2
    public function orX(array $expressions)
54
    {
55 2
        $expr = $this->expr();
56
57 2
        foreach ($expressions as $expression) {
58 2
            $expr->addOr($expression);
59 2
        }
60
61 2
        return $expr;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $expr; (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...onBuilderInterface::orX of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 1
    public function asc($x)
68
    {
69 1
        return $this->expr()->sort($x, 'ASC');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->expr()->sort($x, 'ASC'); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...onBuilderInterface::asc of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 1
    public function desc($x)
76
    {
77 1
        return $this->expr()->sort($x, 'DESC');
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->expr()->sort($x, 'DESC'); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...nBuilderInterface::desc of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 6
    public function eq($x, $y)
84
    {
85 6
        return $this->field($x)->equals($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->equals($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...ionBuilderInterface::eq of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 2
    public function neq($x, $y)
92
    {
93 2
        return $this->field($x)->notEqual($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->notEqual($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...onBuilderInterface::neq of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
94
    }
95
96
    /**
97
     * {@inheritdoc}
98
     */
99 2
    public function lt($x, $y)
100
    {
101 2
        return $this->field($x)->lt($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->lt($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...ionBuilderInterface::lt of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
102
    }
103
104
    /**
105
     * {@inheritdoc}
106
     */
107 2
    public function lte($x, $y)
108
    {
109 2
        return $this->field($x)->lte($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->lte($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...onBuilderInterface::lte of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115 2
    public function gt($x, $y)
116
    {
117 2
        return $this->field($x)->gt($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->gt($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...ionBuilderInterface::gt of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
118
    }
119
120
    /**
121
     * {@inheritdoc}
122
     */
123 2
    public function gte($x, $y)
124
    {
125 2
        return $this->field($x)->gte($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->gte($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...onBuilderInterface::gte of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
126
    }
127
128
    /**
129
     * {@inheritdoc}
130
     */
131 1
    public function exists($x)
132
    {
133 1
        return $this->field($x)->exists(true);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->exists(true); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...uilderInterface::exists of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
134
    }
135
136
    /**
137
     * {@inheritdoc}
138
     */
139 1
    public function in($x, $y)
140
    {
141 1
        return $this->field($x)->in($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->in($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...ionBuilderInterface::in of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
142
    }
143
144
    /**
145
     * {@inheritdoc}
146
     */
147 1
    public function notIn($x, $y)
148
    {
149 1
        return $this->field($x)->notIn($y);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->field($x)->notIn($y); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...BuilderInterface::notIn of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
150
    }
151
152
    /**
153
     * {@inheritdoc}
154
     */
155 1
    public function isNull($x)
156
    {
157 1
        return $this->eq($x, null);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->eq($x, null); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...uilderInterface::isNull of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
158
    }
159
160
    /**
161
     * {@inheritdoc}
162
     */
163 1
    public function isNotNull($x)
164
    {
165 1
        return $this->neq($x, null);
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->neq($x, null); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...derInterface::isNotNull of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
166
    }
167
168
    /**
169
     * {@inheritdoc}
170
     */
171 4
    public function like($x, $y)
172
    {
173 4
        return $this->eq($x, $this->convertLikeToRegex($y));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->eq($x, $th...onvertLikeToRegex($y)); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...nBuilderInterface::like of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
174
    }
175
176
    /**
177
     * {@inheritdoc}
178
     */
179 4
    public function notLike($x, $y)
180
    {
181 4
        return $this->field($x)->not($this->convertLikeToRegex($y));
0 ignored issues
show
Documentation introduced by
$this->convertLikeToRegex($y) is of type object<MongoRegex>, but the function expects a array|object<Doctrine\MongoDB\Query\Expr>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug Best Practice introduced by
The return type of return $this->field($x)-...onvertLikeToRegex($y)); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...ilderInterface::notLike of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
182
    }
183
184
    /**
185
     * {@inheritdoc}
186
     */
187 1
    public function between($value, $x, $y)
188
    {
189 1
        return $this->andX([
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->andX(array...his->lte($value, $y))); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...ilderInterface::between of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
190 1
            $this->gte($value, $x),
191 1
            $this->lte($value, $y),
192 1
        ]);
193
    }
194
195
    /**
196
     * {@inheritdoc}
197
     */
198 1
    public function notBetween($value, $x, $y)
199
    {
200 1
        return $this->orX([
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->orX(array(...this->gt($value, $y))); (Doctrine\ODM\MongoDB\Query\Expr) is incompatible with the return type declared by the interface Lug\Component\Grid\DataS...erInterface::notBetween of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
201 1
            $this->lt($value, $x),
202 1
            $this->gt($value, $y),
203 1
        ]);
204
    }
205
206
    /**
207
     * @param string $field
208
     *
209
     * @return Expr
210
     */
211 21
    private function field($field)
212
    {
213 21
        return $this->expr()->field($field);
214
    }
215
216
    /**
217
     * @return Expr
218
     */
219 25
    private function expr()
220
    {
221 25
        return $this->queryBuilder->expr();
222
    }
223
224
    /**
225
     * @param string $x
226
     *
227
     * @return \MongoRegex
228
     */
229 8
    private function convertLikeToRegex($x)
230
    {
231 8
        $x = preg_quote($x);
232 8
        $pattern = '.*?';
233 8
        $regex = null;
234
235 8
        if (strpos($x, $like = '%') === 0) {
236 4
            $regex .= $pattern;
237 4
            $x = substr($x, 1);
238 4
        }
239
240 8
        if (strrpos($x, $like) === strlen($x) - 1) {
241 4
            $regex .= substr($x, 0, -1).$pattern;
242 4
        } else {
243 4
            $regex .= $x;
244
        }
245
246 8
        return new \MongoRegex('/^'.$regex.'$/');
247
    }
248
}
249