Passed
Push — master ( 9b561d...08d227 )
by y
01:25
created

ComparisonTrait::isNotLike()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Helix\DB\SQL;
4
5
use Helix\DB;
6
use Helix\DB\Select;
7
8
/**
9
 * Produces comparative predicates for the instance.
10
 */
11
trait ComparisonTrait {
12
13
    use PredicateTrait;
14
15
    /**
16
     * @var DB
17
     */
18
    protected $db;
19
20
    /**
21
     * Null-safe equality.
22
     *
23
     * - Mysql: `$this <=> $arg`, or `$this <=> ANY ($arg)`
24
     * - Sqlite: `$this IS $arg`, or `$this IS ANY ($arg)`
25
     *
26
     * @param null|bool|string|Select $arg
27
     * @return Predicate
28
     */
29
    public function is ($arg): Predicate {
30
        if ($arg === null or is_bool($arg)) {
31
            $arg = ['' => 'NULL', 1 => 'TRUE', 0 => 'FALSE'][$arg];
32
        }
33
        else {
34
            $arg = $this->db->quote($arg);
35
        }
36
        $oper = ['mysql' => '<=>', 'sqlite' => 'IS'][$this->db->getDriver()];
37
        return Predicate::compare($this, $arg, $oper, 'ANY');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $arg, $oper, 'ANY');
Loading history...
38
    }
39
40
    /**
41
     * `$this = $arg`, or `$this IN (...$arg)`, or `$this = ANY ($arg)`
42
     *
43
     * @param string|array|Select $arg
44
     * @return Predicate
45
     */
46
    public function isEqual ($arg) {
47
        return Predicate::compare($this, $this->db->quoteMixed($arg));
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

47
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quoteMixed($arg));
Loading history...
48
    }
49
50
    /**
51
     * `$this > $arg`, or `$this > ALL ($arg)`
52
     *
53
     * @param string|Select $arg
54
     * @return Predicate
55
     */
56
    public function isGreater ($arg) {
57
        return Predicate::compare($this, $this->db->quote($arg), '>', 'ALL');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($arg), '>', 'ALL');
Loading history...
58
    }
59
60
    /**
61
     * `$this >= $arg`, or `$this >= ALL ($arg)`
62
     *
63
     * @param string|Select $arg
64
     * @return Predicate
65
     */
66
    public function isGreaterOrEqual ($arg) {
67
        return Predicate::compare($this, $this->db->quote($arg), '>=', 'ALL');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($arg), '>=', 'ALL');
Loading history...
68
    }
69
70
    /**
71
     * `$this < $arg`, or `$this < ALL ($arg)`
72
     *
73
     * @param string|Select $arg
74
     * @return Predicate
75
     */
76
    public function isLess ($arg) {
77
        return Predicate::compare($this, $this->db->quote($arg), '<', 'ALL');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

77
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($arg), '<', 'ALL');
Loading history...
78
    }
79
80
    /**
81
     * `$this <= $arg`, or `$this <= ALL ($arg)`
82
     *
83
     * @param string|Select $arg
84
     * @return Predicate
85
     */
86
    public function isLessOrEqual ($arg) {
87
        return Predicate::compare($this, $this->db->quote($arg), '<=', 'ALL');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($arg), '<=', 'ALL');
Loading history...
88
    }
89
90
    /**
91
     * `$this LIKE $pattern`
92
     *
93
     * @param string $pattern
94
     * @return Predicate
95
     */
96
    public function isLike (string $pattern) {
97
        return Predicate::compare($this, $this->db->quote($pattern), 'LIKE');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

97
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($pattern), 'LIKE');
Loading history...
98
    }
99
100
    /**
101
     * Null-safe inequality.
102
     *
103
     * @param null|bool|string|Select $arg
104
     * @return Predicate
105
     */
106
    public function isNot ($arg) {
107
        return $this->is($arg)->invert();
108
    }
109
110
    /**
111
     * `$this <> $arg`, or `$this NOT IN (...$arg)`, or `$this <> ALL ($arg)`
112
     *
113
     * @param string|array|Select $arg
114
     * @return Predicate
115
     */
116
    public function isNotEqual ($arg) {
117
        return Predicate::compare($this, $this->db->quoteMixed($arg), '<>', 'ALL', 'NOT IN');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

117
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quoteMixed($arg), '<>', 'ALL', 'NOT IN');
Loading history...
118
    }
119
120
    /**
121
     * `$this NOT LIKE $pattern`
122
     *
123
     * @param string $pattern
124
     * @return Predicate
125
     */
126
    public function isNotLike (string $pattern) {
127
        return Predicate::compare($this, $this->db->quote($pattern), 'NOT LIKE');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

127
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($pattern), 'NOT LIKE');
Loading history...
128
    }
129
130
    /**
131
     * `$this NOT REGEXP $pattern`
132
     *
133
     * @param string $pattern
134
     * @return Predicate
135
     */
136
    public function isNotRegExp (string $pattern) {
137
        return Predicate::compare($this, $this->db->quote($pattern), 'NOT REGEXP');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

137
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($pattern), 'NOT REGEXP');
Loading history...
138
    }
139
140
    /**
141
     * `$this REGEXP $pattern`
142
     *
143
     * @param string $pattern
144
     * @return Predicate
145
     */
146
    public function isRegExp (string $pattern) {
147
        return Predicate::compare($this, $this->db->quote($pattern), 'REGEXP');
0 ignored issues
show
Bug introduced by
$this of type Helix\DB\SQL\ComparisonTrait is incompatible with the type string expected by parameter $a of Helix\DB\SQL\Predicate::compare(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

147
        return Predicate::compare(/** @scrutinizer ignore-type */ $this, $this->db->quote($pattern), 'REGEXP');
Loading history...
148
    }
149
}