1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This file is part of Cycle ORM package. |
||
5 | * |
||
6 | * For the full copyright and license information, please view the LICENSE |
||
7 | * file that was distributed with this source code. |
||
8 | */ |
||
9 | |||
10 | declare(strict_types=1); |
||
11 | |||
12 | namespace Cycle\Database\Query; |
||
13 | |||
14 | use Cycle\Database\Driver\CompilerInterface; |
||
15 | use Cycle\Database\Query\Traits\TokenTrait; |
||
16 | use Cycle\Database\Query\Traits\WhereJsonTrait; |
||
17 | use Cycle\Database\Query\Traits\WhereTrait; |
||
18 | |||
19 | /** |
||
20 | * Update statement builder. |
||
21 | */ |
||
22 | class UpdateQuery extends ActiveQuery |
||
23 | { |
||
24 | use TokenTrait; |
||
25 | use WhereJsonTrait; |
||
26 | use WhereTrait; |
||
27 | |||
28 | 78 | protected string $table = ''; |
|
29 | |||
30 | public function __construct( |
||
31 | ?string $table = null, |
||
32 | array $where = [], |
||
33 | 78 | protected array $values = [], |
|
34 | ) { |
||
35 | 78 | $this->table = $table ?? ''; |
|
36 | |||
37 | if ($where !== []) { |
||
38 | 78 | $this->where($where); |
|
39 | } |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * Change target table. |
||
44 | * |
||
45 | 122 | * @psalm-param non-empty-string $table Table name without prefix. |
|
46 | */ |
||
47 | 122 | public function in(string $table): self |
|
48 | { |
||
49 | 122 | $this->table = $table; |
|
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Change value set to be updated, must be represented by array of columns associated with new |
||
56 | 128 | * value to be set. |
|
57 | */ |
||
58 | 128 | public function values(array $values): self |
|
59 | { |
||
60 | 128 | $this->values = $values; |
|
61 | |||
62 | return $this; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Set update value. |
||
67 | * |
||
68 | 34 | * @psalm-param non-empty-string $column |
|
69 | */ |
||
70 | 34 | public function set(string $column, mixed $value): self |
|
71 | { |
||
72 | 34 | $this->values[$column] = $value; |
|
73 | |||
74 | return $this; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | 64 | * Affect queries will return count of affected rows. |
|
79 | */ |
||
80 | 64 | public function run(): int |
|
81 | 64 | { |
|
82 | $params = new QueryParameters(); |
||
83 | 64 | $queryString = $this->sqlStatement($params); |
|
84 | |||
85 | return $this->driver->execute($queryString, $params->getParameters()); |
||
0 ignored issues
–
show
|
|||
86 | 106 | } |
|
87 | |||
88 | 106 | public function getType(): int |
|
89 | { |
||
90 | return CompilerInterface::UPDATE_QUERY; |
||
91 | 106 | } |
|
92 | |||
93 | public function getTokens(): array |
||
94 | 106 | { |
|
95 | 106 | return [ |
|
96 | 106 | 'table' => $this->table, |
|
97 | 'values' => $this->values, |
||
98 | 'where' => $this->whereTokens, |
||
99 | ]; |
||
100 | } |
||
101 | } |
||
102 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.