1 | <?php declare(strict_types=1); |
||||||
2 | |||||||
3 | /* |
||||||
4 | * This file is part of the Koded package. |
||||||
5 | * |
||||||
6 | * (c) Mihail Binev <[email protected]> |
||||||
7 | * |
||||||
8 | * Please view the LICENSE distributed with this source code |
||||||
9 | * for the full copyright and license information. |
||||||
10 | */ |
||||||
11 | |||||||
12 | namespace Koded\Stdlib; |
||||||
13 | |||||||
14 | /** |
||||||
15 | * @property array $data |
||||||
16 | */ |
||||||
17 | trait MutatorTrait |
||||||
18 | { |
||||||
19 | 5 | public function __set($index, $value) |
|||||
20 | { |
||||||
21 | 5 | return $this->set($index, $value); |
|||||
22 | } |
||||||
23 | |||||||
24 | 18 | public function set(string $index, mixed $value): static |
|||||
25 | { |
||||||
26 | 18 | $this->data[$index] = $value; |
|||||
27 | 18 | return $this; |
|||||
28 | } |
||||||
29 | |||||||
30 | 1 | public function bind(string $index, mixed &$variable): static |
|||||
31 | { |
||||||
32 | 1 | $this->data[$index] =& $variable; |
|||||
33 | 1 | return $this; |
|||||
34 | } |
||||||
35 | |||||||
36 | 1 | public function upsert(string $index, mixed $value): static |
|||||
37 | { |
||||||
38 | 1 | return $this->has($index) ? $this : $this->set($index, $value); |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
39 | } |
||||||
40 | |||||||
41 | 1 | public function pull(string $index, mixed $default = null): mixed |
|||||
42 | { |
||||||
43 | 1 | $value = $this->get($index, $default); |
|||||
0 ignored issues
–
show
It seems like
get() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
44 | 1 | unset($this->data[$index]); |
|||||
45 | 1 | return $value; |
|||||
46 | } |
||||||
47 | |||||||
48 | 18 | public function import(array $array): static |
|||||
49 | { |
||||||
50 | 18 | foreach ($array as $index => $value) { |
|||||
51 | 17 | $this->data[$index] = $value; |
|||||
52 | } |
||||||
53 | 18 | return $this; |
|||||
54 | } |
||||||
55 | |||||||
56 | 3 | public function delete(string $index): static |
|||||
57 | { |
||||||
58 | 3 | unset($this->data[$index]); |
|||||
59 | 3 | return $this; |
|||||
60 | } |
||||||
61 | |||||||
62 | 1 | public function clear(): static |
|||||
63 | { |
||||||
64 | 1 | $this->data = []; |
|||||
65 | 1 | return $this; |
|||||
66 | } |
||||||
67 | } |
||||||
68 |