@@ -23,7 +23,7 @@ |
||
23 | 23 | |
24 | 24 | return ("`" . $this->name . "` int(10) unsigned NOT NULL") . |
25 | 25 | |
26 | - ($this->auto_increment ? " AUTO_INCREMENT" : ""); |
|
26 | + ($this->auto_increment ? " AUTO_INCREMENT" : ""); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | # Cast value |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | return ("`" . $this->name . "` " . ($this->short ? ("varchar(" . $this->maxlength . ")") : "text")) . |
27 | 27 | |
28 | - (($this->binary ? " CHARACTER SET utf8 COLLATE utf8_bin" : "") . " NOT NULL"); |
|
28 | + (($this->binary ? " CHARACTER SET utf8 COLLATE utf8_bin" : "") . " NOT NULL"); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | # Cast value |
@@ -16,7 +16,9 @@ |
||
16 | 16 | |
17 | 17 | # Set field configuration |
18 | 18 | |
19 | - foreach (get_defined_vars() as $name => $value) $this->$name = $value; |
|
19 | + foreach (get_defined_vars() as $name => $value) { |
|
20 | + $this->$name = $value; |
|
21 | + } |
|
20 | 22 | } |
21 | 23 | |
22 | 24 | # Get field statement |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | return ("`" . $this->name . "` " . ($this->short ? "tiny" : "") . "int(" . $this->maxlength . ") ") . |
27 | 27 | |
28 | - ("unsigned NOT NULL DEFAULT '" . $this->default . "'"); |
|
28 | + ("unsigned NOT NULL DEFAULT '" . $this->default . "'"); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | # Cast value |
@@ -16,7 +16,9 @@ |
||
16 | 16 | |
17 | 17 | # Set field configuration |
18 | 18 | |
19 | - foreach (get_defined_vars() as $name => $value) $this->$name = $value; |
|
19 | + foreach (get_defined_vars() as $name => $value) { |
|
20 | + $this->$name = $value; |
|
21 | + } |
|
20 | 22 | } |
21 | 23 | |
22 | 24 | # Get field statement |
@@ -40,7 +40,7 @@ |
||
40 | 40 | |
41 | 41 | return ($this->index ? (($this->unique ? ($this->primary ? "PRIMARY " : "UNIQUE ") : "") . |
42 | 42 | |
43 | - ("KEY `" . $this->name . "` (`" . $this->name . "`)")) : false); |
|
43 | + ("KEY `" . $this->name . "` (`" . $this->name . "`)")) : false); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | } |
@@ -12,7 +12,9 @@ discard block |
||
12 | 12 | |
13 | 13 | private function addParam(Param $param) { |
14 | 14 | |
15 | - if (('' === $param->name()) || isset($this->params[$param->name()])) return; |
|
15 | + if (('' === $param->name()) || isset($this->params[$param->name()])) { |
|
16 | + return; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | $this->params[$param->name()] = $param; |
18 | 20 | } |
@@ -26,7 +28,9 @@ discard block |
||
26 | 28 | |
27 | 29 | foreach ($this->params as $param) { |
28 | 30 | |
29 | - if (false !== ($statement = $param->$method())) $statements[] = $statement; |
|
31 | + if (false !== ($statement = $param->$method())) { |
|
32 | + $statements[] = $statement; |
|
33 | + } |
|
30 | 34 | } |
31 | 35 | |
32 | 36 | # ------------------------ |
@@ -63,7 +67,9 @@ discard block |
||
63 | 67 | |
64 | 68 | protected function addOrderer(string $name, bool $descending = false) { |
65 | 69 | |
66 | - if (!isset($this->params[$name]) || isset($this->orderers[$name])) return; |
|
70 | + if (!isset($this->params[$name]) || isset($this->orderers[$name])) { |
|
71 | + return; |
|
72 | + } |
|
67 | 73 | |
68 | 74 | $this->orderers[$name] = $descending; |
69 | 75 | } |
@@ -128,10 +134,12 @@ discard block |
||
128 | 134 | |
129 | 135 | $params = []; |
130 | 136 | |
131 | - foreach ($data as $name => $value) if (isset($this->params[$name])) { |
|
137 | + foreach ($data as $name => $value) { |
|
138 | + if (isset($this->params[$name])) { |
|
132 | 139 | |
133 | 140 | $params[$name] = $this->params[$name]->cast($value); |
134 | 141 | } |
142 | + } |
|
135 | 143 | |
136 | 144 | # ------------------------ |
137 | 145 |
@@ -36,17 +36,17 @@ |
||
36 | 36 | |
37 | 37 | $query = ("SELECT SQL_CALC_FOUND_ROWS ent.id, " . implode(', ', $selection)) . |
38 | 38 | |
39 | - (static::$nesting ? ", COUNT(chd.id) as children " : " ") . |
|
39 | + (static::$nesting ? ", COUNT(chd.id) as children " : " ") . |
|
40 | 40 | |
41 | - ("FROM " . static::$table . " ent ") . |
|
41 | + ("FROM " . static::$table . " ent ") . |
|
42 | 42 | |
43 | - (static::$nesting ? ("LEFT JOIN " . static::$table . " chd ON chd.parent_id = ent.id ") : "") . |
|
43 | + (static::$nesting ? ("LEFT JOIN " . static::$table . " chd ON chd.parent_id = ent.id ") : "") . |
|
44 | 44 | |
45 | - ("WHERE ent.id != " . $disable_id . " ") . |
|
45 | + ("WHERE ent.id != " . $disable_id . " ") . |
|
46 | 46 | |
47 | - (static::$nesting ? ("AND ent.parent_id = " . $parent_id . " GROUP BY ent.id ") : "") . |
|
47 | + (static::$nesting ? ("AND ent.parent_id = " . $parent_id . " GROUP BY ent.id ") : "") . |
|
48 | 48 | |
49 | - ("ORDER BY " . implode(', ', $order_by) . ", ent.id ASC" . ($limit ? (" LIMIT " . $limit) : "")); |
|
49 | + ("ORDER BY " . implode(', ', $order_by) . ", ent.id ASC" . ($limit ? (" LIMIT " . $limit) : "")); |
|
50 | 50 | |
51 | 51 | # ------------------------ |
52 | 52 |
@@ -66,13 +66,17 @@ |
||
66 | 66 | |
67 | 67 | $items = ['list' => [], 'total' => 0]; |
68 | 68 | |
69 | - if (!(($index >= 0) && ($display >= 0) && ($parent_id >= 0) && ($disable_id >= 0))) return $items; |
|
69 | + if (!(($index >= 0) && ($display >= 0) && ($parent_id >= 0) && ($disable_id >= 0))) { |
|
70 | + return $items; |
|
71 | + } |
|
70 | 72 | |
71 | 73 | # Select entities |
72 | 74 | |
73 | 75 | $query = $this->getQuery($index, $display, $parent_id, $disable_id); |
74 | 76 | |
75 | - if (!(DB::send($query) && DB::last()->status)) return $items; |
|
77 | + if (!(DB::send($query) && DB::last()->status)) { |
|
78 | + return $items; |
|
79 | + } |
|
76 | 80 | |
77 | 81 | # Process results |
78 | 82 |
@@ -12,25 +12,35 @@ |
||
12 | 12 | |
13 | 13 | public function create(array $data) { |
14 | 14 | |
15 | - if (0 !== $this->id) return false; |
|
15 | + if (0 !== $this->id) { |
|
16 | + return false; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | $set = $this->getDataset($data, true); |
18 | 20 | |
19 | - if (isset($set['id']) && !($set['id'] > 0)) return false; |
|
21 | + if (isset($set['id']) && !($set['id'] > 0)) { |
|
22 | + return false; |
|
23 | + } |
|
20 | 24 | |
21 | 25 | # Insert entity |
22 | 26 | |
23 | 27 | DB::insert(static::$table, $set); |
24 | 28 | |
25 | - if (!(DB::last() && DB::last()->status)) return false; |
|
29 | + if (!(DB::last() && DB::last()->status)) { |
|
30 | + return false; |
|
31 | + } |
|
26 | 32 | |
27 | 33 | # Re-init entity |
28 | 34 | |
29 | 35 | $this->error = false; $this->id = DB::last()->id; |
30 | 36 | |
31 | - foreach ($set as $name => $value) if ($name !== 'id') $this->data[$name] = $value; |
|
37 | + foreach ($set as $name => $value) { |
|
38 | + if ($name !== 'id') $this->data[$name] = $value; |
|
39 | + } |
|
32 | 40 | |
33 | - if (static::$nesting) $this->data['path'] = $this->getPath(); |
|
41 | + if (static::$nesting) { |
|
42 | + $this->data['path'] = $this->getPath(); |
|
43 | + } |
|
34 | 44 | |
35 | 45 | # Implement entity |
36 | 46 |
@@ -12,13 +12,19 @@ discard block |
||
12 | 12 | |
13 | 13 | public function remove() { |
14 | 14 | |
15 | - if (0 === $this->id) return false; |
|
15 | + if (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->children())) return false; |
|
25 | + if (static::$nesting && (0 !== $this->children())) { |
|
26 | + return false; |
|
27 | + } |
|
22 | 28 | |
23 | 29 | # Remove extension entries |
24 | 30 | |
@@ -26,18 +32,24 @@ discard block |
||
26 | 32 | |
27 | 33 | $entity = self::get($extension, $this->id); |
28 | 34 | |
29 | - if ($entity->error() || ((0 !== $entity->id) && !$entity->remove())) return false; |
|
35 | + if ($entity->error() || ((0 !== $entity->id) && !$entity->remove())) { |
|
36 | + return false; |
|
37 | + } |
|
30 | 38 | } |
31 | 39 | |
32 | 40 | # Remove entity |
33 | 41 | |
34 | 42 | DB::delete(static::$table, ['id' => $this->id]); |
35 | 43 | |
36 | - if (!(DB::last() && DB::last()->status)) return false; |
|
44 | + if (!(DB::last() && DB::last()->status)) { |
|
45 | + return false; |
|
46 | + } |
|
37 | 47 | |
38 | 48 | # Uncache entity |
39 | 49 | |
40 | - if (self::$cache[static::$type][$this->id] === $this) unset(self::$cache[static::$type][$this->id]); |
|
50 | + if (self::$cache[static::$type][$this->id] === $this) { |
|
51 | + unset(self::$cache[static::$type][$this->id]); |
|
52 | + } |
|
41 | 53 | |
42 | 54 | # Reset id |
43 | 55 | |
@@ -45,11 +57,15 @@ discard block |
||
45 | 57 | |
46 | 58 | # Reset data array |
47 | 59 | |
48 | - foreach ($this->definition->params() as $name => $param) $this->data[$name] = $param->cast(null); |
|
60 | + foreach ($this->definition->params() as $name => $param) { |
|
61 | + $this->data[$name] = $param->cast(null); |
|
62 | + } |
|
49 | 63 | |
50 | 64 | # Reset path |
51 | 65 | |
52 | - if (static::$nesting) $this->data['path'] = []; |
|
66 | + if (static::$nesting) { |
|
67 | + $this->data['path'] = []; |
|
68 | + } |
|
53 | 69 | |
54 | 70 | # Implement entity |
55 | 71 |
@@ -12,13 +12,17 @@ discard block |
||
12 | 12 | |
13 | 13 | public function init($value, string $name = 'id') { |
14 | 14 | |
15 | - if (0 !== $this->id) return false; |
|
15 | + if (0 !== $this->id) { |
|
16 | + return false; |
|
17 | + } |
|
16 | 18 | |
17 | 19 | # Check param name |
18 | 20 | |
19 | - if ($name === 'id') $param = $this->definition->id(); |
|
20 | - |
|
21 | - else if ((false === ($param = $this->definition->get($name))) || !$param->unique()) return false; |
|
21 | + if ($name === 'id') { |
|
22 | + $param = $this->definition->id(); |
|
23 | + } else if ((false === ($param = $this->definition->get($name))) || !$param->unique()) { |
|
24 | + return false; |
|
25 | + } |
|
22 | 26 | |
23 | 27 | # Select entity from DB |
24 | 28 | |
@@ -28,7 +32,9 @@ discard block |
||
28 | 32 | |
29 | 33 | DB::select(static::$table, $selection, [$name => $value], null, 1); |
30 | 34 | |
31 | - if (($this->error = !(DB::last() && DB::last()->status)) || (DB::last()->rows !== 1)) return false; |
|
35 | + if (($this->error = !(DB::last() && DB::last()->status)) || (DB::last()->rows !== 1)) { |
|
36 | + return false; |
|
37 | + } |
|
32 | 38 | |
33 | 39 | $data = DB::last()->row(); |
34 | 40 | |
@@ -36,11 +42,15 @@ discard block |
||
36 | 42 | |
37 | 43 | $this->id = $this->definition->id()->cast($data['id']); |
38 | 44 | |
39 | - foreach ($this->definition->params() as $name => $param) $this->data[$name] = $param->cast($data[$name]); |
|
45 | + foreach ($this->definition->params() as $name => $param) { |
|
46 | + $this->data[$name] = $param->cast($data[$name]); |
|
47 | + } |
|
40 | 48 | |
41 | 49 | # Init path |
42 | 50 | |
43 | - if (static::$nesting) $this->data['path'] = $this->getPath(); |
|
51 | + if (static::$nesting) { |
|
52 | + $this->data['path'] = $this->getPath(); |
|
53 | + } |
|
44 | 54 | |
45 | 55 | # Implement entity |
46 | 56 |