@@ -19,7 +19,7 @@ |
||
19 | 19 | |
20 | 20 | public function statement() { |
21 | 21 | |
22 | - return ("`" . $this->name . "` int(10) UNSIGNED NOT NULL" . ($this->auto_increment ? " AUTO_INCREMENT" : "")); |
|
22 | + return ("`".$this->name."` int(10) UNSIGNED NOT NULL".($this->auto_increment ? " AUTO_INCREMENT" : "")); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | # Cast value |
@@ -23,7 +23,7 @@ |
||
23 | 23 | |
24 | 24 | return ("`" . $this->name . "` " . ($this->short ? "tiny" : "") . "int(" . $this->length . ")") . |
25 | 25 | |
26 | - (($this->unsigned ? " UNSIGNED" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
26 | + (($this->unsigned ? " UNSIGNED" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | # Cast value |
@@ -21,9 +21,9 @@ |
||
21 | 21 | |
22 | 22 | public function statement() { |
23 | 23 | |
24 | - return ("`" . $this->name . "` " . ($this->short ? "tiny" : "") . "int(" . $this->length . ")") . |
|
24 | + return ("`".$this->name."` ".($this->short ? "tiny" : "")."int(".$this->length.")"). |
|
25 | 25 | |
26 | - (($this->unsigned ? " UNSIGNED" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
26 | + (($this->unsigned ? " UNSIGNED" : "")." NOT NULL DEFAULT '".$this->default."'"); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | # Cast value |
@@ -23,7 +23,7 @@ |
||
23 | 23 | |
24 | 24 | return ("`" . $this->name . "` " . ($this->short ? ("varchar(" . $this->length . ")") : "text")) . |
25 | 25 | |
26 | - (($this->binary ? " BINARY" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
26 | + (($this->binary ? " BINARY" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | # Cast value |
@@ -21,9 +21,9 @@ |
||
21 | 21 | |
22 | 22 | public function statement() { |
23 | 23 | |
24 | - return ("`" . $this->name . "` " . ($this->short ? ("varchar(" . $this->length . ")") : "text")) . |
|
24 | + return ("`".$this->name."` ".($this->short ? ("varchar(".$this->length.")") : "text")). |
|
25 | 25 | |
26 | - (($this->binary ? " BINARY" : "") . " NOT NULL DEFAULT '" . $this->default . "'"); |
|
26 | + (($this->binary ? " BINARY" : "")." NOT NULL DEFAULT '".$this->default."'"); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | # Cast value |
@@ -21,7 +21,7 @@ |
||
21 | 21 | |
22 | 22 | public function statement() { |
23 | 23 | |
24 | - return ("`" . $this->name . "` tinyint(1) UNSIGNED NOT NULL DEFAULT '" . intval($this->default) . "'"); |
|
24 | + return ("`".$this->name."` tinyint(1) UNSIGNED NOT NULL DEFAULT '".intval($this->default)."'"); |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | # Cast value |
@@ -12,19 +12,27 @@ discard block |
||
12 | 12 | |
13 | 13 | public function remove() { |
14 | 14 | |
15 | - if (!$this->modifiable || (0 === $this->id)) return false; |
|
15 | + if (!$this->modifiable || (0 === $this->id)) { |
|
16 | + return false; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | # Check if entity is removable |
18 | 20 | |
19 | - if (static::$super && ($this->id === 1)) return false; |
|
21 | + if (static::$super && ($this->id === 1)) { |
|
22 | + return false; |
|
23 | + } |
|
20 | 24 | |
21 | - if (static::$nesting && (0 !== $this->subtreeCount())) return false; |
|
25 | + if (static::$nesting && (0 !== $this->subtreeCount())) { |
|
26 | + return false; |
|
27 | + } |
|
22 | 28 | |
23 | 29 | # Remove entity |
24 | 30 | |
25 | 31 | DB::delete(static::$table, ['id' => $this->id]); |
26 | 32 | |
27 | - if (!(DB::last() && DB::last()->status)) return false; |
|
33 | + if (!(DB::last() && DB::last()->status)) { |
|
34 | + return false; |
|
35 | + } |
|
28 | 36 | |
29 | 37 | # Uncache entity |
30 | 38 | |
@@ -37,7 +45,9 @@ discard block |
||
37 | 45 | |
38 | 46 | $this->data = $this->definition->cast([], true); |
39 | 47 | |
40 | - if (static::$nesting) $this->data['parent_id'] = 0; |
|
48 | + if (static::$nesting) { |
|
49 | + $this->data['parent_id'] = 0; |
|
50 | + } |
|
41 | 51 | |
42 | 52 | # Implement entity |
43 | 53 |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | $query = ("DELETE rla FROM " . static::$table_relations . " rla ") . |
29 | 29 | |
30 | - ("JOIN " . static::$table_relations . " rlb ON rlb.descendant = rla.descendant ") . |
|
30 | + ("JOIN " . static::$table_relations . " rlb ON rlb.descendant = rla.descendant ") . |
|
31 | 31 | |
32 | 32 | ("LEFT JOIN " . static::$table_relations . " rlx ") . |
33 | 33 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | |
53 | 53 | $query = ("INSERT INTO " . static::$table_relations . " (ancestor, descendant, depth) ") . |
54 | 54 | |
55 | - ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 ") . |
|
55 | + ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 ") . |
|
56 | 56 | |
57 | 57 | ("FROM " . static::$table_relations . " sup ") . |
58 | 58 |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | private function disconnectSubtree() { |
27 | 27 | |
28 | - $query = ("DELETE rla FROM " . static::$table_relations . " rla ") . |
|
28 | + $query = ("DELETE rla FROM ".static::$table_relations." rla "). |
|
29 | 29 | |
30 | - ("JOIN " . static::$table_relations . " rlb ON rlb.descendant = rla.descendant ") . |
|
30 | + ("JOIN ".static::$table_relations." rlb ON rlb.descendant = rla.descendant "). |
|
31 | 31 | |
32 | - ("LEFT JOIN " . static::$table_relations . " rlx ") . |
|
32 | + ("LEFT JOIN ".static::$table_relations." rlx "). |
|
33 | 33 | |
34 | - ("ON rlx.ancestor = rlb.ancestor AND rlx.descendant = rla.ancestor ") . |
|
34 | + ("ON rlx.ancestor = rlb.ancestor AND rlx.descendant = rla.ancestor "). |
|
35 | 35 | |
36 | - ("WHERE rlb.ancestor = " . $this->id . " AND rlx.ancestor IS NULL"); |
|
36 | + ("WHERE rlb.ancestor = ".$this->id." AND rlx.ancestor IS NULL"); |
|
37 | 37 | |
38 | 38 | if (!(DB::send($query) && DB::last()->status)) return false; |
39 | 39 | |
@@ -50,15 +50,15 @@ discard block |
||
50 | 50 | |
51 | 51 | private function connectSubtree(int $parent_id) { |
52 | 52 | |
53 | - $query = ("INSERT INTO " . static::$table_relations . " (ancestor, descendant, depth) ") . |
|
53 | + $query = ("INSERT INTO ".static::$table_relations." (ancestor, descendant, depth) "). |
|
54 | 54 | |
55 | - ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 ") . |
|
55 | + ("SELECT sup.ancestor, sub.descendant, sup.depth + sub.depth + 1 "). |
|
56 | 56 | |
57 | - ("FROM " . static::$table_relations . " sup ") . |
|
57 | + ("FROM ".static::$table_relations." sup "). |
|
58 | 58 | |
59 | - ("JOIN " . static::$table_relations . " sub ") . |
|
59 | + ("JOIN ".static::$table_relations." sub "). |
|
60 | 60 | |
61 | - ("WHERE sub.ancestor = " . $this->id . " AND sup.descendant = " . $parent_id); |
|
61 | + ("WHERE sub.ancestor = ".$this->id." AND sup.descendant = ".$parent_id); |
|
62 | 62 | |
63 | 63 | if (!(DB::send($query) && DB::last()->status)) return false; |
64 | 64 |
@@ -35,7 +35,9 @@ discard block |
||
35 | 35 | |
36 | 36 | ("WHERE rlb.ancestor = " . $this->id . " AND rlx.ancestor IS NULL"); |
37 | 37 | |
38 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
38 | + if (!(DB::send($query) && DB::last()->status)) { |
|
39 | + return false; |
|
40 | + } |
|
39 | 41 | |
40 | 42 | # Set path |
41 | 43 | |
@@ -60,7 +62,9 @@ discard block |
||
60 | 62 | |
61 | 63 | ("WHERE sub.ancestor = " . $this->id . " AND sup.descendant = " . $parent_id); |
62 | 64 | |
63 | - if (!(DB::send($query) && DB::last()->status)) return false; |
|
65 | + if (!(DB::send($query) && DB::last()->status)) { |
|
66 | + return false; |
|
67 | + } |
|
64 | 68 | |
65 | 69 | # Set path |
66 | 70 | |
@@ -75,25 +79,35 @@ discard block |
||
75 | 79 | |
76 | 80 | public function create(array $data) { |
77 | 81 | |
78 | - if (!$this->modifiable || (0 !== $this->id)) return false; |
|
82 | + if (!$this->modifiable || (0 !== $this->id)) { |
|
83 | + return false; |
|
84 | + } |
|
79 | 85 | |
80 | 86 | $data = $this->definition->cast($data); |
81 | 87 | |
82 | - if (static::$auto_increment && isset($data['id'])) unset($data['id']); |
|
88 | + if (static::$auto_increment && isset($data['id'])) { |
|
89 | + unset($data['id']); |
|
90 | + } |
|
83 | 91 | |
84 | 92 | # Insert entity |
85 | 93 | |
86 | 94 | DB::insert(static::$table, $data); |
87 | 95 | |
88 | - if (!(DB::last() && DB::last()->status)) return false; |
|
96 | + if (!(DB::last() && DB::last()->status)) { |
|
97 | + return false; |
|
98 | + } |
|
89 | 99 | |
90 | 100 | # Set data |
91 | 101 | |
92 | 102 | $this->error = false; |
93 | 103 | |
94 | - if (static::$auto_increment) $this->data['id'] = DB::last()->id; |
|
104 | + if (static::$auto_increment) { |
|
105 | + $this->data['id'] = DB::last()->id; |
|
106 | + } |
|
95 | 107 | |
96 | - foreach ($data as $name => $value) $this->data[$name] = $value; |
|
108 | + foreach ($data as $name => $value) { |
|
109 | + $this->data[$name] = $value; |
|
110 | + } |
|
97 | 111 | |
98 | 112 | # Implement entity |
99 | 113 | |
@@ -101,7 +115,9 @@ discard block |
||
101 | 115 | |
102 | 116 | # Init subtreee |
103 | 117 | |
104 | - if (static::$nesting) $this->initSubtree(); |
|
118 | + if (static::$nesting) { |
|
119 | + $this->initSubtree(); |
|
120 | + } |
|
105 | 121 | |
106 | 122 | # Cache entity |
107 | 123 | |
@@ -116,21 +132,29 @@ discard block |
||
116 | 132 | |
117 | 133 | public function edit(array $data) { |
118 | 134 | |
119 | - if (!$this->modifiable || (0 === $this->id)) return false; |
|
135 | + if (!$this->modifiable || (0 === $this->id)) { |
|
136 | + return false; |
|
137 | + } |
|
120 | 138 | |
121 | 139 | $data = $this->definition->cast($data); |
122 | 140 | |
123 | - if (isset($data['id'])) unset($data['id']); |
|
141 | + if (isset($data['id'])) { |
|
142 | + unset($data['id']); |
|
143 | + } |
|
124 | 144 | |
125 | 145 | # Update entity |
126 | 146 | |
127 | 147 | DB::update(static::$table, $data, ['id' => $this->id]); |
128 | 148 | |
129 | - if (!(DB::last() && DB::last()->status)) return false; |
|
149 | + if (!(DB::last() && DB::last()->status)) { |
|
150 | + return false; |
|
151 | + } |
|
130 | 152 | |
131 | 153 | # Set data |
132 | 154 | |
133 | - foreach ($data as $name => $value) $this->data[$name] = $value; |
|
155 | + foreach ($data as $name => $value) { |
|
156 | + $this->data[$name] = $value; |
|
157 | + } |
|
134 | 158 | |
135 | 159 | # Implement entity |
136 | 160 | |
@@ -138,7 +162,9 @@ discard block |
||
138 | 162 | |
139 | 163 | # Init subtreee |
140 | 164 | |
141 | - if (static::$nesting) $this->initSubtree(); |
|
165 | + if (static::$nesting) { |
|
166 | + $this->initSubtree(); |
|
167 | + } |
|
142 | 168 | |
143 | 169 | # ------------------------ |
144 | 170 | |
@@ -149,30 +175,44 @@ discard block |
||
149 | 175 | |
150 | 176 | public function move(int $parent_id) { |
151 | 177 | |
152 | - if (!$this->modifiable || (0 === $this->id)) return false; |
|
178 | + if (!$this->modifiable || (0 === $this->id)) { |
|
179 | + return false; |
|
180 | + } |
|
153 | 181 | |
154 | 182 | # Re-connect entity if not in tree |
155 | 183 | |
156 | - if (!$this->initSubtree()) return false; |
|
184 | + if (!$this->initSubtree()) { |
|
185 | + return false; |
|
186 | + } |
|
157 | 187 | |
158 | 188 | # Create parent entity |
159 | 189 | |
160 | 190 | if (0 !== ($parent = Entitizer::get(static::$table, $parent_id))->id) { |
161 | 191 | |
162 | - if (false === ($path = $parent->path())) return false; |
|
192 | + if (false === ($path = $parent->path())) { |
|
193 | + return false; |
|
194 | + } |
|
163 | 195 | |
164 | - if (false === ($depth = $this->subtreeDepth())) return false; |
|
196 | + if (false === ($depth = $this->subtreeDepth())) { |
|
197 | + return false; |
|
198 | + } |
|
165 | 199 | |
166 | - if ((count($path) + $depth + 1) > CONFIG_ENTITIZER_MAX_DEPTH) return false; |
|
200 | + if ((count($path) + $depth + 1) > CONFIG_ENTITIZER_MAX_DEPTH) { |
|
201 | + return false; |
|
202 | + } |
|
167 | 203 | } |
168 | 204 | |
169 | 205 | # Disconnect subtree from current position |
170 | 206 | |
171 | - if (!$this->disconnectSubtree()) return false; |
|
207 | + if (!$this->disconnectSubtree()) { |
|
208 | + return false; |
|
209 | + } |
|
172 | 210 | |
173 | 211 | # Connect subtree under new position |
174 | 212 | |
175 | - if (0 !== $parent->id) $this->connectSubtree($parent->id); |
|
213 | + if (0 !== $parent->id) { |
|
214 | + $this->connectSubtree($parent->id); |
|
215 | + } |
|
176 | 216 | |
177 | 217 | # ------------------------ |
178 | 218 |
@@ -30,9 +30,9 @@ |
||
30 | 30 | |
31 | 31 | $query = ("CREATE TABLE IF NOT EXISTS `" . static::$table . "` (") . |
32 | 32 | |
33 | - implode(", ", $this->getStatements()) . |
|
33 | + implode(", ", $this->getStatements()) . |
|
34 | 34 | |
35 | - (") ENGINE=InnoDB DEFAULT CHARSET=utf8"); |
|
35 | + (") ENGINE=InnoDB DEFAULT CHARSET=utf8"); |
|
36 | 36 | |
37 | 37 | # ------------------------ |
38 | 38 |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | |
29 | 29 | private function createMainTable() { |
30 | 30 | |
31 | - $query = ("CREATE TABLE IF NOT EXISTS `" . static::$table . "` (") . |
|
31 | + $query = ("CREATE TABLE IF NOT EXISTS `".static::$table."` ("). |
|
32 | 32 | |
33 | - implode(", ", $this->getStatements()) . |
|
33 | + implode(", ", $this->getStatements()). |
|
34 | 34 | |
35 | 35 | (") ENGINE=InnoDB DEFAULT CHARSET=utf8"); |
36 | 36 | |
@@ -43,17 +43,17 @@ discard block |
||
43 | 43 | |
44 | 44 | private function createRelationsTable() { |
45 | 45 | |
46 | - $query = ("CREATE TABLE IF NOT EXISTS `" . static::$table_relations . "` (") . |
|
46 | + $query = ("CREATE TABLE IF NOT EXISTS `".static::$table_relations."` ("). |
|
47 | 47 | |
48 | - ("`ancestor` int(10) UNSIGNED NOT NULL, `descendant` int(10) UNSIGNED NOT NULL, ") . |
|
48 | + ("`ancestor` int(10) UNSIGNED NOT NULL, `descendant` int(10) UNSIGNED NOT NULL, "). |
|
49 | 49 | |
50 | - ("`depth` int(10) UNSIGNED NOT NULL, ") . |
|
50 | + ("`depth` int(10) UNSIGNED NOT NULL, "). |
|
51 | 51 | |
52 | - ("PRIMARY KEY (`ancestor`, `descendant`), KEY (`ancestor`), KEY (`descendant`), KEY (`depth`), ") . |
|
52 | + ("PRIMARY KEY (`ancestor`, `descendant`), KEY (`ancestor`), KEY (`descendant`), KEY (`depth`), "). |
|
53 | 53 | |
54 | - ("FOREIGN KEY (`ancestor`) REFERENCES `" . static::$table . "` (`id`) ON DELETE CASCADE, ") . |
|
54 | + ("FOREIGN KEY (`ancestor`) REFERENCES `".static::$table."` (`id`) ON DELETE CASCADE, "). |
|
55 | 55 | |
56 | - ("FOREIGN KEY (`descendant`) REFERENCES `" . static::$table . "` (`id`) ON DELETE CASCADE ") . |
|
56 | + ("FOREIGN KEY (`descendant`) REFERENCES `".static::$table."` (`id`) ON DELETE CASCADE "). |
|
57 | 57 | |
58 | 58 | (") ENGINE=InnoDB DEFAULT CHARSET=utf8"); |
59 | 59 |
@@ -16,7 +16,9 @@ discard block |
||
16 | 16 | |
17 | 17 | foreach ([$this->params, $this->indexes, $this->foreigns] as $group) { |
18 | 18 | |
19 | - foreach ($group->list() as $item) $statements[] = $item->statement(); |
|
19 | + foreach ($group->list() as $item) { |
|
20 | + $statements[] = $item->statement(); |
|
21 | + } |
|
20 | 22 | } |
21 | 23 | |
22 | 24 | # ------------------------ |
@@ -134,9 +136,11 @@ discard block |
||
134 | 136 | |
135 | 137 | foreach ($this->params->list() as $name => $param) { |
136 | 138 | |
137 | - if ($process_all) $cast[$name] = $param->cast($data[$name] ?? null); |
|
138 | - |
|
139 | - else if (isset($data[$name])) $cast[$name] = $param->cast($data[$name]); |
|
139 | + if ($process_all) { |
|
140 | + $cast[$name] = $param->cast($data[$name] ?? null); |
|
141 | + } else if (isset($data[$name])) { |
|
142 | + $cast[$name] = $param->cast($data[$name]); |
|
143 | + } |
|
140 | 144 | } |
141 | 145 | |
142 | 146 | # ------------------------ |
@@ -24,11 +24,11 @@ |
||
24 | 24 | |
25 | 25 | $query = ("SELECT " . implode(', ', $selection) .", rel.ancestor as parent_id ") . |
26 | 26 | |
27 | - ("FROM " . static::$table . " ent ") . |
|
27 | + ("FROM " . static::$table . " ent ") . |
|
28 | 28 | |
29 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
29 | + ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
30 | 30 | |
31 | - ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
31 | + ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
32 | 32 | |
33 | 33 | # ------------------------ |
34 | 34 |
@@ -18,17 +18,17 @@ discard block |
||
18 | 18 | |
19 | 19 | $selection = array_keys($this->definition->params()); |
20 | 20 | |
21 | - foreach ($selection as $key => $field) $selection[$key] = ('ent.' . $field); |
|
21 | + foreach ($selection as $key => $field) $selection[$key] = ('ent.'.$field); |
|
22 | 22 | |
23 | 23 | # Process query |
24 | 24 | |
25 | - $query = ("SELECT " . implode(', ', $selection) .", rel.ancestor as parent_id ") . |
|
25 | + $query = ("SELECT ".implode(', ', $selection).", rel.ancestor as parent_id "). |
|
26 | 26 | |
27 | - ("FROM " . static::$table . " ent ") . |
|
27 | + ("FROM ".static::$table." ent "). |
|
28 | 28 | |
29 | - ("LEFT JOIN " . static::$table_relations . " rel ON rel.descendant = ent.id AND rel.depth = 1 ") . |
|
29 | + ("LEFT JOIN ".static::$table_relations." rel ON rel.descendant = ent.id AND rel.depth = 1 "). |
|
30 | 30 | |
31 | - ("WHERE ent." . $name . " = '" . addslashes($value) . "' LIMIT 1"); |
|
31 | + ("WHERE ent.".$name." = '".addslashes($value)."' LIMIT 1"); |
|
32 | 32 | |
33 | 33 | # ------------------------ |
34 | 34 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | # Select entity from DB |
135 | 135 | |
136 | - $condition = ($name . " = '" . addslashes($value) . "' AND id != " . $this->id); |
|
136 | + $condition = ($name." = '".addslashes($value)."' AND id != ".$this->id); |
|
137 | 137 | |
138 | 138 | DB::select(static::$table, 'id', $condition, null, 1); |
139 | 139 |
@@ -18,7 +18,9 @@ discard block |
||
18 | 18 | |
19 | 19 | $selection = array_keys($this->definition->params()); |
20 | 20 | |
21 | - foreach ($selection as $key => $field) $selection[$key] = ('ent.' . $field); |
|
21 | + foreach ($selection as $key => $field) { |
|
22 | + $selection[$key] = ('ent.' . $field); |
|
23 | + } |
|
22 | 24 | |
23 | 25 | # Process query |
24 | 26 | |
@@ -43,7 +45,9 @@ discard block |
||
43 | 45 | |
44 | 46 | $this->data = $this->definition->cast($data, true); |
45 | 47 | |
46 | - if (static::$nesting) $this->data['parent_id'] = intval($data['parent_id'] ?? 0); |
|
48 | + if (static::$nesting) { |
|
49 | + $this->data['parent_id'] = intval($data['parent_id'] ?? 0); |
|
50 | + } |
|
47 | 51 | |
48 | 52 | # Implement entity |
49 | 53 | |
@@ -68,7 +72,9 @@ discard block |
||
68 | 72 | |
69 | 73 | # Check data |
70 | 74 | |
71 | - if ([] === $data) $this->modifiable = true; |
|
75 | + if ([] === $data) { |
|
76 | + $this->modifiable = true; |
|
77 | + } |
|
72 | 78 | |
73 | 79 | # Preset data |
74 | 80 | |
@@ -76,7 +82,9 @@ discard block |
||
76 | 82 | |
77 | 83 | # Preset parent id |
78 | 84 | |
79 | - if (static::$nesting) $this->data['parent_id'] = 0; |
|
85 | + if (static::$nesting) { |
|
86 | + $this->data['parent_id'] = 0; |
|
87 | + } |
|
80 | 88 | |
81 | 89 | # Implement entity |
82 | 90 | |
@@ -87,13 +95,19 @@ discard block |
||
87 | 95 | |
88 | 96 | public function init($value, string $name = 'id') { |
89 | 97 | |
90 | - if (!$this->modifiable || (0 !== $this->id)) return false; |
|
98 | + if (!$this->modifiable || (0 !== $this->id)) { |
|
99 | + return false; |
|
100 | + } |
|
91 | 101 | |
92 | 102 | # Get initiation index |
93 | 103 | |
94 | - if (false === ($index = $this->definition->index($name))) return false; |
|
104 | + if (false === ($index = $this->definition->index($name))) { |
|
105 | + return false; |
|
106 | + } |
|
95 | 107 | |
96 | - if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) return false; |
|
108 | + if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) { |
|
109 | + return false; |
|
110 | + } |
|
97 | 111 | |
98 | 112 | # Process name & value |
99 | 113 | |
@@ -101,14 +115,18 @@ discard block |
||
101 | 115 | |
102 | 116 | # Select entity from DB |
103 | 117 | |
104 | - if (static::$nesting) $this->selectNesting($name, $value); else { |
|
118 | + if (static::$nesting) { |
|
119 | + $this->selectNesting($name, $value); |
|
120 | + } else { |
|
105 | 121 | |
106 | 122 | $selection = array_keys($this->definition->params()); |
107 | 123 | |
108 | 124 | DB::select(static::$table, $selection, [$name => $value], null, 1); |
109 | 125 | } |
110 | 126 | |
111 | - if (($this->error = !(DB::last() && DB::last()->status)) || (DB::last()->rows !== 1)) return false; |
|
127 | + if (($this->error = !(DB::last() && DB::last()->status)) || (DB::last()->rows !== 1)) { |
|
128 | + return false; |
|
129 | + } |
|
112 | 130 | |
113 | 131 | # ------------------------ |
114 | 132 | |
@@ -119,13 +137,19 @@ discard block |
||
119 | 137 | |
120 | 138 | public function check($value, string $name) { |
121 | 139 | |
122 | - if (!$this->modifiable) return false; |
|
140 | + if (!$this->modifiable) { |
|
141 | + return false; |
|
142 | + } |
|
123 | 143 | |
124 | 144 | # Get initiation index |
125 | 145 | |
126 | - if (false === ($index = $this->definition->index($name))) return false; |
|
146 | + if (false === ($index = $this->definition->index($name))) { |
|
147 | + return false; |
|
148 | + } |
|
127 | 149 | |
128 | - if ($index->type !== 'UNIQUE') return false; |
|
150 | + if ($index->type !== 'UNIQUE') { |
|
151 | + return false; |
|
152 | + } |
|
129 | 153 | |
130 | 154 | # Process name & value |
131 | 155 |
@@ -12,9 +12,13 @@ |
||
12 | 12 | |
13 | 13 | public static function get(string $table) { |
14 | 14 | |
15 | - if (!isset(static::$classes[$table])) throw new Exception\General(static::$error_message); |
|
15 | + if (!isset(static::$classes[$table])) { |
|
16 | + throw new Exception\General(static::$error_message); |
|
17 | + } |
|
16 | 18 | |
17 | - if (isset(static::$cache[$table])) return static::$cache[$table]; |
|
19 | + if (isset(static::$cache[$table])) { |
|
20 | + return static::$cache[$table]; |
|
21 | + } |
|
18 | 22 | |
19 | 23 | # ------------------------ |
20 | 24 |