@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | */ |
10 | 10 | trait TextTrait { |
11 | 11 | |
12 | - abstract public function __toString (); |
|
12 | + abstract public function __toString(); |
|
13 | 13 | |
14 | 14 | /** |
15 | 15 | * @var DB |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * @return Text |
21 | 21 | */ |
22 | - public function getHex () { |
|
22 | + public function getHex() { |
|
23 | 23 | return Text::factory($this->db, "HEX({$this})"); |
24 | 24 | } |
25 | 25 | |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * |
31 | 31 | * @return Numeric |
32 | 32 | */ |
33 | - public function getLength () { |
|
33 | + public function getLength() { |
|
34 | 34 | if ($this->db->isSQLite()) { |
35 | 35 | return Numeric::factory($this->db, "LENGTH(CAST({$this} AS TEXT))"); |
36 | 36 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return Text |
44 | 44 | */ |
45 | - public function getLower () { |
|
45 | + public function getLower() { |
|
46 | 46 | return Text::factory($this->db, "LOWER({$this})"); |
47 | 47 | } |
48 | 48 | |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param string $substring |
55 | 55 | * @return Numeric |
56 | 56 | */ |
57 | - public function getPosition (string $substring) { |
|
57 | + public function getPosition(string $substring) { |
|
58 | 58 | $substring = $this->db->quote($substring); |
59 | 59 | if ($this->db->isSQLite()) { |
60 | 60 | return Numeric::factory($this->db, "INSTR({$this},{$substring})"); |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @param string $replace |
70 | 70 | * @return Text |
71 | 71 | */ |
72 | - public function getReplacement (string $search, string $replace) { |
|
72 | + public function getReplacement(string $search, string $replace) { |
|
73 | 73 | $search = $this->db->quote($search); |
74 | 74 | $replace = $this->db->quote($replace); |
75 | 75 | return Text::factory($this->db, "REPLACE({$this},{$search},{$replace})"); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return Numeric |
82 | 82 | */ |
83 | - public function getSize () { |
|
83 | + public function getSize() { |
|
84 | 84 | if ($this->db->isSQLite()) { |
85 | 85 | return Numeric::factory($this->db, "LENGTH(CAST({$this} AS BLOB))"); |
86 | 86 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @param null|int $length |
95 | 95 | * @return Text |
96 | 96 | */ |
97 | - public function getSubstring (int $start, int $length = null) { |
|
97 | + public function getSubstring(int $start, int $length = null) { |
|
98 | 98 | if (isset($length)) { |
99 | 99 | return Text::factory($this->db, "SUBSTR({$this},{$start},{$length})"); |
100 | 100 | } |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @return Text |
108 | 108 | */ |
109 | - public function getUpper () { |
|
109 | + public function getUpper() { |
|
110 | 110 | return Text::factory($this->db, "UPPER({$this})"); |
111 | 111 | } |
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -17,7 +17,7 @@ |
||
17 | 17 | * @param array $args The first argument must be a {@link DB} instance. |
18 | 18 | * @return static |
19 | 19 | */ |
20 | - public static function __callStatic (string $ignored, array $args) { |
|
20 | + public static function __callStatic(string $ignored, array $args) { |
|
21 | 21 | /** @var DB $db */ |
22 | 22 | $db = $args[0]; |
23 | 23 | unset($args[0]); |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @param DB $db |
16 | 16 | * @param string $name |
17 | 17 | */ |
18 | - public function __construct (DB $db, string $name) { |
|
18 | + public function __construct(DB $db, string $name) { |
|
19 | 19 | parent::__construct($db, $name, ['entity', 'attribute', 'value']); |
20 | 20 | } |
21 | 21 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param string $attribute |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function exists (int $id, string $attribute): bool { |
|
29 | + public function exists(int $id, string $attribute): bool { |
|
30 | 30 | $exists = $this->cache(__FUNCTION__, function() { |
31 | 31 | $select = $this->select(['COUNT(*) > 0']); |
32 | 32 | $select->where('entity = ? AND attribute = ?'); |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * @param array $match `[attribute => value]`. If empty, selects all IDs for entities having at least one attribute. |
45 | 45 | * @return Select |
46 | 46 | */ |
47 | - public function find (array $match) { |
|
47 | + public function find(array $match) { |
|
48 | 48 | $select = $this->select([$this['entity']]); |
49 | 49 | $prior = $this; |
50 | 50 | foreach ($match as $attribute => $value) { |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @param int $id |
67 | 67 | * @return array `[attribute => value]` |
68 | 68 | */ |
69 | - public function load (int $id): array { |
|
69 | + public function load(int $id): array { |
|
70 | 70 | $load = $this->cache(__FUNCTION__, function() { |
71 | 71 | $select = $this->select(['attribute', 'value']); |
72 | 72 | $select->where('entity = ?'); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | * @param int[] $ids |
83 | 83 | * @return array[] `[id => attribute => value] |
84 | 84 | */ |
85 | - public function loadAll (array $ids): array { |
|
85 | + public function loadAll(array $ids): array { |
|
86 | 86 | if (empty($ids)) { |
87 | 87 | return []; |
88 | 88 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param array $values `[attribute => value]` |
108 | 108 | * @return $this |
109 | 109 | */ |
110 | - public function save (int $id, array $values) { |
|
110 | + public function save(int $id, array $values) { |
|
111 | 111 | $this->delete([ |
112 | 112 | $this['entity']->isEqual($id), |
113 | 113 | $this['attribute']->isNotEqual(array_keys($values)) |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param string $name |
43 | 43 | * @param string[] $columns |
44 | 44 | */ |
45 | - public function __construct (DB $db, string $name, array $columns) { |
|
45 | + public function __construct(DB $db, string $name, array $columns) { |
|
46 | 46 | parent::__construct($db); |
47 | 47 | $this->name = $name; |
48 | 48 | foreach ($columns as $column) { |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * |
56 | 56 | * @return string |
57 | 57 | */ |
58 | - final public function __toString () { |
|
58 | + final public function __toString() { |
|
59 | 59 | return $this->name; |
60 | 60 | } |
61 | 61 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param array $values |
66 | 66 | * @return int Rows affected. |
67 | 67 | */ |
68 | - public function apply (array $values): int { |
|
68 | + public function apply(array $values): int { |
|
69 | 69 | $columns = implode(',', array_keys($values)); |
70 | 70 | $values = $this->db->quoteList($values); |
71 | 71 | switch ($this->db) { |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | * @param Closure $prepare `():Statement` |
88 | 88 | * @return Statement |
89 | 89 | */ |
90 | - protected function cache (string $key, Closure $prepare) { |
|
90 | + protected function cache(string $key, Closure $prepare) { |
|
91 | 91 | return $this->_cache[$key] ?? $this->_cache[$key] = $prepare->__invoke(); |
92 | 92 | } |
93 | 93 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @param array $match `[a => b]` |
96 | 96 | * @return int |
97 | 97 | */ |
98 | - public function count (array $match = []) { |
|
98 | + public function count(array $match = []) { |
|
99 | 99 | $select = $this->select(['COUNT(*)']); |
100 | 100 | foreach ($match as $a => $b) { |
101 | 101 | $select->where($this->db->match($this[$a] ?? $a, $b)); |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | * @param array $match |
112 | 112 | * @return int Rows affected. |
113 | 113 | */ |
114 | - public function delete (array $match): int { |
|
114 | + public function delete(array $match): int { |
|
115 | 115 | foreach ($match as $a => $b) { |
116 | 116 | $match[$a] = $this->db->match($this[$a] ?? $a, $b); |
117 | 117 | } |
@@ -122,14 +122,14 @@ discard block |
||
122 | 122 | /** |
123 | 123 | * @return Column[] |
124 | 124 | */ |
125 | - final public function getColumns (): array { |
|
125 | + final public function getColumns(): array { |
|
126 | 126 | return $this->columns; |
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - final public function getName (): string { |
|
132 | + final public function getName(): string { |
|
133 | 133 | return $this->name; |
134 | 134 | } |
135 | 135 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | * @param array $values |
140 | 140 | * @return Statement |
141 | 141 | */ |
142 | - public function insert (array $values) { |
|
142 | + public function insert(array $values) { |
|
143 | 143 | $columns = implode(',', array_keys($values)); |
144 | 144 | $values = $this->db->quoteList($values); |
145 | 145 | return $this->db->query("INSERT INTO {$this} ($columns) VALUES ($values)"); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param int|string $column |
150 | 150 | * @return Column |
151 | 151 | */ |
152 | - public function offsetGet ($column) { |
|
152 | + public function offsetGet($column) { |
|
153 | 153 | if (is_int($column)) { |
154 | 154 | return current(array_slice($this->columns, $column, 1)) ?: null; |
155 | 155 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param string[] $columns Defaults to all columns. |
163 | 163 | * @return Select |
164 | 164 | */ |
165 | - public function select (array $columns = []) { |
|
165 | + public function select(array $columns = []) { |
|
166 | 166 | if (empty($columns)) { |
167 | 167 | $columns = $this->columns; |
168 | 168 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | * @param string $name |
176 | 176 | * @return Table |
177 | 177 | */ |
178 | - public function setName (string $name) { |
|
178 | + public function setName(string $name) { |
|
179 | 179 | $clone = clone $this; |
180 | 180 | $clone->name = $name; |
181 | 181 | foreach ($this->columns as $name => $column) { |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | * @param array $match |
194 | 194 | * @return int Rows affected. |
195 | 195 | */ |
196 | - public function update (array $values, array $match): int { |
|
196 | + public function update(array $values, array $match): int { |
|
197 | 197 | foreach ($this->db->quoteArray($values) as $key => $value) { |
198 | 198 | $values[$key] = "{$key} = {$value}"; |
199 | 199 | } |