Issues (55)

src/Schema/Operations.php (2 issues)

1
<?php
2
3
/**
4
 * This file is part of the tarantool/client package.
5
 *
6
 * (c) Eugene Leonovich <[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
declare(strict_types=1);
13
14
namespace Tarantool\Client\Schema;
15
16
final class Operations
17
{
18
    /** @var non-empty-array<int, array> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array<int, array> at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array<int, array>.
Loading history...
19
    private $operations;
20
21
    /**
22
     * @param non-empty-array<int, mixed> $operation
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-array<int, mixed> at position 0 could not be parsed: Unknown type name 'non-empty-array' at position 0 in non-empty-array<int, mixed>.
Loading history...
23
     */
24 64
    private function __construct($operation)
25
    {
26 64
        $this->operations = [$operation];
27
    }
28
29
    /**
30
     * @param int|string $field
31
     */
32 4
    public static function add($field, int $value) : self
33
    {
34 4
        return new self(['+', $field, $value]);
35
    }
36
37
    /**
38
     * @param int|string $field
39
     */
40 4
    public function andAdd($field, int $value) : self
41
    {
42 4
        $new = clone $this;
43 4
        $new->operations[] = ['+', $field, $value];
44
45 4
        return $new;
46
    }
47
48
    /**
49
     * @param int|string $field
50
     */
51 4
    public static function subtract($field, int $value) : self
52
    {
53 4
        return new self(['-', $field, $value]);
54
    }
55
56
    /**
57
     * @param int|string $field
58
     */
59 4
    public function andSubtract($field, int $value) : self
60
    {
61 4
        $new = clone $this;
62 4
        $new->operations[] = ['-', $field, $value];
63
64 4
        return $new;
65
    }
66
67
    /**
68
     * @param int|string $field
69
     */
70 4
    public static function bitwiseAnd($field, int $value) : self
71
    {
72 4
        return new self(['&', $field, $value]);
73
    }
74
75
    /**
76
     * @param int|string $field
77
     */
78 4
    public function andBitwiseAnd($field, int $value) : self
79
    {
80 4
        $new = clone $this;
81 4
        $new->operations[] = ['&', $field, $value];
82
83 4
        return $new;
84
    }
85
86
    /**
87
     * @param int|string $field
88
     */
89 4
    public static function bitwiseOr($field, int $value) : self
90
    {
91 4
        return new self(['|', $field, $value]);
92
    }
93
94
    /**
95
     * @param int|string $field
96
     */
97 4
    public function andBitwiseOr($field, int $value) : self
98
    {
99 4
        $new = clone $this;
100 4
        $new->operations[] = ['|', $field, $value];
101
102 4
        return $new;
103
    }
104
105
    /**
106
     * @param int|string $field
107
     */
108 4
    public static function bitwiseXor($field, int $value) : self
109
    {
110 4
        return new self(['^', $field, $value]);
111
    }
112
113
    /**
114
     * @param int|string $field
115
     */
116 4
    public function andBitwiseXor($field, int $value) : self
117
    {
118 4
        $new = clone $this;
119 4
        $new->operations[] = ['^', $field, $value];
120
121 4
        return $new;
122
    }
123
124
    /**
125
     * @param int|string $field
126
     */
127 16
    public static function splice($field, int $offset, int $length, string $replacement) : self
128
    {
129 16
        return new self([':', $field, $offset, $length, $replacement]);
130
    }
131
132
    /**
133
     * @param int|string $field
134
     */
135 4
    public function andSplice($field, int $offset, int $length, string $replacement) : self
136
    {
137 4
        $new = clone $this;
138 4
        $new->operations[] = [':', $field, $offset, $length, $replacement];
139
140 4
        return $new;
141
    }
142
143
    /**
144
     * @param int|string $field
145
     */
146 4
    public static function insert($field, int $value) : self
147
    {
148 4
        return new self(['!', $field, $value]);
149
    }
150
151
    /**
152
     * @param int|string $field
153
     */
154 4
    public function andInsert($field, int $value) : self
155
    {
156 4
        $new = clone $this;
157 4
        $new->operations[] = ['!', $field, $value];
158
159 4
        return $new;
160
    }
161
162
    /**
163
     * @param int|string $field
164
     */
165 4
    public static function delete($field, int $value) : self
166
    {
167 4
        return new self(['#', $field, $value]);
168
    }
169
170
    /**
171
     * @param int|string $field
172
     */
173 4
    public function andDelete($field, int $value) : self
174
    {
175 4
        $new = clone $this;
176 4
        $new->operations[] = ['#', $field, $value];
177
178 4
        return $new;
179
    }
180
181
    /**
182
     * @param int|string $field
183
     * @param mixed $value
184
     */
185 20
    public static function set($field, $value) : self
186
    {
187 20
        return new self(['=', $field, $value]);
188
    }
189
190
    /**
191
     * @param int|string $field
192
     * @param mixed $value
193
     */
194 4
    public function andSet($field, $value) : self
195
    {
196 4
        $new = clone $this;
197 4
        $new->operations[] = ['=', $field, $value];
198
199 4
        return $new;
200
    }
201
202 80
    public function toArray() : array
203
    {
204 80
        return $this->operations;
205
    }
206
}
207