@@ -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()->rows > 0))) return false; |
|
65 | + if (!(DB::send($query) && (DB::last()->rows > 0))) { |
|
66 | + return false; |
|
67 | + } |
|
64 | 68 | |
65 | 69 | # Set path |
66 | 70 | |
@@ -75,27 +79,37 @@ discard block |
||
75 | 79 | |
76 | 80 | public function create(array $data) { |
77 | 81 | |
78 | - if (0 !== $this->id) return false; |
|
82 | + if (0 !== $this->id) { |
|
83 | + return false; |
|
84 | + } |
|
79 | 85 | |
80 | 86 | $data = $this->dataset->cast($data); |
81 | 87 | |
82 | - if (static::$auto_increment && isset($data['id'])) $data['id'] = 0; |
|
88 | + if (static::$auto_increment && isset($data['id'])) { |
|
89 | + $data['id'] = 0; |
|
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 | # Update data |
91 | 101 | |
92 | - if (static::$auto_increment) $data['id'] = DB::last()->id; |
|
102 | + if (static::$auto_increment) { |
|
103 | + $data['id'] = DB::last()->id; |
|
104 | + } |
|
93 | 105 | |
94 | 106 | $this->dataset->update($data); |
95 | 107 | |
96 | 108 | # Init subtreee |
97 | 109 | |
98 | - if (static::$nesting) $this->initSubtree(); |
|
110 | + if (static::$nesting) { |
|
111 | + $this->initSubtree(); |
|
112 | + } |
|
99 | 113 | |
100 | 114 | # Cache entity |
101 | 115 | |
@@ -110,17 +124,23 @@ discard block |
||
110 | 124 | |
111 | 125 | public function edit(array $data) { |
112 | 126 | |
113 | - if (0 === $this->id) return false; |
|
127 | + if (0 === $this->id) { |
|
128 | + return false; |
|
129 | + } |
|
114 | 130 | |
115 | 131 | $data = $this->dataset->cast($data); |
116 | 132 | |
117 | - if (isset($data['id'])) unset($data['id']); |
|
133 | + if (isset($data['id'])) { |
|
134 | + unset($data['id']); |
|
135 | + } |
|
118 | 136 | |
119 | 137 | # Update entity |
120 | 138 | |
121 | 139 | DB::update(static::$table, $data, ['id' => $this->id]); |
122 | 140 | |
123 | - if (!(DB::last() && DB::last()->status)) return false; |
|
141 | + if (!(DB::last() && DB::last()->status)) { |
|
142 | + return false; |
|
143 | + } |
|
124 | 144 | |
125 | 145 | # Update data |
126 | 146 | |
@@ -128,7 +148,9 @@ discard block |
||
128 | 148 | |
129 | 149 | # Init subtreee |
130 | 150 | |
131 | - if (static::$nesting) $this->initSubtree(); |
|
151 | + if (static::$nesting) { |
|
152 | + $this->initSubtree(); |
|
153 | + } |
|
132 | 154 | |
133 | 155 | # ------------------------ |
134 | 156 | |
@@ -139,30 +161,44 @@ discard block |
||
139 | 161 | |
140 | 162 | public function move(int $parent_id) { |
141 | 163 | |
142 | - if (0 === $this->id) return false; |
|
164 | + if (0 === $this->id) { |
|
165 | + return false; |
|
166 | + } |
|
143 | 167 | |
144 | 168 | # Re-connect entity if not in tree |
145 | 169 | |
146 | - if (!$this->initSubtree()) return false; |
|
170 | + if (!$this->initSubtree()) { |
|
171 | + return false; |
|
172 | + } |
|
147 | 173 | |
148 | 174 | # Create parent entity |
149 | 175 | |
150 | 176 | if (0 !== ($parent = Entitizer::get(static::$table, $parent_id))->id) { |
151 | 177 | |
152 | - if (false === ($path = $parent->path())) return false; |
|
178 | + if (false === ($path = $parent->path())) { |
|
179 | + return false; |
|
180 | + } |
|
153 | 181 | |
154 | - if (false === ($depth = $this->subtreeDepth())) return false; |
|
182 | + if (false === ($depth = $this->subtreeDepth())) { |
|
183 | + return false; |
|
184 | + } |
|
155 | 185 | |
156 | - if ((count($path) + $depth + 1) > CONFIG_ENTITIZER_MAX_DEPTH) return false; |
|
186 | + if ((count($path) + $depth + 1) > CONFIG_ENTITIZER_MAX_DEPTH) { |
|
187 | + return false; |
|
188 | + } |
|
157 | 189 | } |
158 | 190 | |
159 | 191 | # Disconnect subtree from current position |
160 | 192 | |
161 | - if (!$this->disconnectSubtree()) return false; |
|
193 | + if (!$this->disconnectSubtree()) { |
|
194 | + return false; |
|
195 | + } |
|
162 | 196 | |
163 | 197 | # Connect subtree under new position |
164 | 198 | |
165 | - if (0 !== $parent->id) $this->connectSubtree($parent->id); |
|
199 | + if (0 !== $parent->id) { |
|
200 | + $this->connectSubtree($parent->id); |
|
201 | + } |
|
166 | 202 | |
167 | 203 | # ------------------------ |
168 | 204 | |
@@ -173,19 +209,27 @@ discard block |
||
173 | 209 | |
174 | 210 | public function remove() { |
175 | 211 | |
176 | - if (0 === $this->id) return false; |
|
212 | + if (0 === $this->id) { |
|
213 | + return false; |
|
214 | + } |
|
177 | 215 | |
178 | 216 | # Check if entity is removable |
179 | 217 | |
180 | - if (static::$super && ($this->id === 1)) return false; |
|
218 | + if (static::$super && ($this->id === 1)) { |
|
219 | + return false; |
|
220 | + } |
|
181 | 221 | |
182 | - if (static::$nesting && (0 !== $this->subtreeCount())) return false; |
|
222 | + if (static::$nesting && (0 !== $this->subtreeCount())) { |
|
223 | + return false; |
|
224 | + } |
|
183 | 225 | |
184 | 226 | # Remove entity |
185 | 227 | |
186 | 228 | DB::delete(static::$table, ['id' => $this->id]); |
187 | 229 | |
188 | - if (!(DB::last() && DB::last()->status)) return false; |
|
230 | + if (!(DB::last() && DB::last()->status)) { |
|
231 | + return false; |
|
232 | + } |
|
189 | 233 | |
190 | 234 | # Uncache entity |
191 | 235 |
@@ -19,7 +19,9 @@ |
||
19 | 19 | |
20 | 20 | public function add(string $name, string $type = null) { |
21 | 21 | |
22 | - if ((false === $this->definition->param($name)) || isset($this->list[$name])) return; |
|
22 | + if ((false === $this->definition->param($name)) || isset($this->list[$name])) { |
|
23 | + return; |
|
24 | + } |
|
23 | 25 | |
24 | 26 | $this->list[$name] = new Definition\Item\Index($name, $type); |
25 | 27 | } |
@@ -10,7 +10,9 @@ |
||
10 | 10 | |
11 | 11 | public function add(string $name, string $table, string $field, string $delete = null, string $update = null) { |
12 | 12 | |
13 | - if ((false === $this->definition->param($name)) || isset($this->list[$name])) return; |
|
13 | + if ((false === $this->definition->param($name)) || isset($this->list[$name])) { |
|
14 | + return; |
|
15 | + } |
|
14 | 16 | |
15 | 17 | $this->list[$name] = new Definition\Item\Foreign($name, $table, $field, $delete, $update); |
16 | 18 | } |
@@ -27,7 +27,9 @@ discard block |
||
27 | 27 | |
28 | 28 | $selection = array_keys($this->definition->params()); |
29 | 29 | |
30 | - foreach ($selection as $key => $field) $selection[$key] = ('ent.' . $field); |
|
30 | + foreach ($selection as $key => $field) { |
|
31 | + $selection[$key] = ('ent.' . $field); |
|
32 | + } |
|
31 | 33 | |
32 | 34 | # Process query |
33 | 35 | |
@@ -87,13 +89,19 @@ discard block |
||
87 | 89 | |
88 | 90 | public function init($value, string $name = 'id') { |
89 | 91 | |
90 | - if (0 !== $this->id) return false; |
|
92 | + if (0 !== $this->id) { |
|
93 | + return false; |
|
94 | + } |
|
91 | 95 | |
92 | 96 | # Get initiation index |
93 | 97 | |
94 | - if (false === ($index = $this->definition->index($name))) return false; |
|
98 | + if (false === ($index = $this->definition->index($name))) { |
|
99 | + return false; |
|
100 | + } |
|
95 | 101 | |
96 | - if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) return false; |
|
102 | + if (($index->type !== 'PRIMARY') && ($index->type !== 'UNIQUE')) { |
|
103 | + return false; |
|
104 | + } |
|
97 | 105 | |
98 | 106 | # Process name & value |
99 | 107 | |
@@ -101,7 +109,11 @@ discard block |
||
101 | 109 | |
102 | 110 | # Select entity from DB |
103 | 111 | |
104 | - if (!static::$nesting) $this->selectDefault($name, $value); else $this->selectNesting($name, $value); |
|
112 | + if (!static::$nesting) { |
|
113 | + $this->selectDefault($name, $value); |
|
114 | + } else { |
|
115 | + $this->selectNesting($name, $value); |
|
116 | + } |
|
105 | 117 | |
106 | 118 | # ------------------------ |
107 | 119 | |
@@ -114,9 +126,13 @@ discard block |
||
114 | 126 | |
115 | 127 | # Get initiation index |
116 | 128 | |
117 | - if (false === ($index = $this->definition->index($name))) return false; |
|
129 | + if (false === ($index = $this->definition->index($name))) { |
|
130 | + return false; |
|
131 | + } |
|
118 | 132 | |
119 | - if ($index->type !== 'UNIQUE') return false; |
|
133 | + if ($index->type !== 'UNIQUE') { |
|
134 | + return false; |
|
135 | + } |
|
120 | 136 | |
121 | 137 | # Process name & value |
122 | 138 |
@@ -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])) static::$cache[$table] = new static::$classes[$table]; |
|
19 | + if (!isset(static::$cache[$table])) { |
|
20 | + static::$cache[$table] = new static::$classes[$table]; |
|
21 | + } |
|
18 | 22 | |
19 | 23 | # ------------------------ |
20 | 24 |
@@ -25,9 +25,13 @@ |
||
25 | 25 | |
26 | 26 | public static function get(string $table, int $id = 0) { |
27 | 27 | |
28 | - if (!isset(self::$classes[$table])) throw new Exception\General(self::$error_message); |
|
28 | + if (!isset(self::$classes[$table])) { |
|
29 | + throw new Exception\General(self::$error_message); |
|
30 | + } |
|
29 | 31 | |
30 | - if (isset(self::$cache[$table][$id])) return self::$cache[$table][$id]; |
|
32 | + if (isset(self::$cache[$table][$id])) { |
|
33 | + return self::$cache[$table][$id]; |
|
34 | + } |
|
31 | 35 | |
32 | 36 | $entity = new self::$classes[$table]; $entity->init($id); |
33 | 37 |