@@ -86,7 +86,7 @@ |
||
| 86 | 86 | |
| 87 | 87 | $name = $param->name(); $value = $param->cast($value); |
| 88 | 88 | |
| 89 | - $condition = ($name . " = '" . addslashes($value) . "' AND id != " . $this->id); |
|
| 89 | + $condition = ($name." = '".addslashes($value)."' AND id != ".$this->id); |
|
| 90 | 90 | |
| 91 | 91 | DB::select(static::$table, 'id', $condition, null, 1); |
| 92 | 92 | |
@@ -20,7 +20,9 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | $entity = self::get(static::$type, $entity->data['parent_id']); |
| 22 | 22 | |
| 23 | - if (0 === $entity->id) return []; |
|
| 23 | + if (0 === $entity->id) { |
|
| 24 | + return []; |
|
| 25 | + } |
|
| 24 | 26 | |
| 25 | 27 | $path[] = array_merge(['id' => $entity->id], $entity->data); |
| 26 | 28 | } |
@@ -44,7 +46,9 @@ discard block |
||
| 44 | 46 | |
| 45 | 47 | # Preset path |
| 46 | 48 | |
| 47 | - if (static::$nesting) $this->data['path'] = []; |
|
| 49 | + if (static::$nesting) { |
|
| 50 | + $this->data['path'] = []; |
|
| 51 | + } |
|
| 48 | 52 | |
| 49 | 53 | # Implement entity |
| 50 | 54 | |
@@ -52,14 +56,18 @@ discard block |
||
| 52 | 56 | |
| 53 | 57 | # Init entity |
| 54 | 58 | |
| 55 | - if ($id > 0) $this->init($id); |
|
| 59 | + if ($id > 0) { |
|
| 60 | + $this->init($id); |
|
| 61 | + } |
|
| 56 | 62 | } |
| 57 | 63 | |
| 58 | 64 | # Check if unique param value exists |
| 59 | 65 | |
| 60 | 66 | public function check(string $name, $value) { |
| 61 | 67 | |
| 62 | - if ((false === ($param = $this->definition->get($name))) || !$param->unique()) return false; |
|
| 68 | + if ((false === ($param = $this->definition->get($name))) || !$param->unique()) { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 63 | 71 | |
| 64 | 72 | # Select entity from DB |
| 65 | 73 | |
@@ -80,7 +88,9 @@ discard block |
||
| 80 | 88 | |
| 81 | 89 | DB::select(static::$table, 'COUNT(id) as count', ['parent_id' => $this->id]); |
| 82 | 90 | |
| 83 | - if (!(DB::last() && DB::last()->status)) return false; |
|
| 91 | + if (!(DB::last() && DB::last()->status)) { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 84 | 94 | |
| 85 | 95 | # ------------------------ |
| 86 | 96 | |
@@ -112,7 +122,9 @@ discard block |
||
| 112 | 122 | |
| 113 | 123 | public function __get(string $name) { |
| 114 | 124 | |
| 115 | - if ($name === 'id') return $this->id; |
|
| 125 | + if ($name === 'id') { |
|
| 126 | + return $this->id; |
|
| 127 | + } |
|
| 116 | 128 | |
| 117 | 129 | return (isset($this->data[$name]) ? $this->data[$name] : null); |
| 118 | 130 | } |
@@ -85,9 +85,9 @@ |
||
| 85 | 85 | |
| 86 | 86 | $set = array_merge($this->getStatements('fieldStatement'), $this->getStatements('keyStatement')); |
| 87 | 87 | |
| 88 | - $query = ("CREATE TABLE IF NOT EXISTS `" . static::$table . "`") . |
|
| 88 | + $query = ("CREATE TABLE IF NOT EXISTS `".static::$table."`"). |
|
| 89 | 89 | |
| 90 | - ("(" . implode(", ", $set) . ") ENGINE=InnoDB DEFAULT CHARSET=utf8"); |
|
| 90 | + ("(".implode(", ", $set).") ENGINE=InnoDB DEFAULT CHARSET=utf8"); |
|
| 91 | 91 | |
| 92 | 92 | # ------------------------ |
| 93 | 93 | |
@@ -12,7 +12,9 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | private function addParam(Param $param) { |
| 14 | 14 | |
| 15 | - if (('' === ($name = $param->name())) || isset($this->params[$name]) || isset($this->implementors[$name])) return; |
|
| 15 | + if (('' === ($name = $param->name())) || isset($this->params[$name]) || isset($this->implementors[$name])) { |
|
| 16 | + return; |
|
| 17 | + } |
|
| 16 | 18 | |
| 17 | 19 | $this->params[$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 | } |
@@ -72,7 +78,9 @@ discard block |
||
| 72 | 78 | |
| 73 | 79 | protected function addImplementor(string $name, callable $callback) { |
| 74 | 80 | |
| 75 | - if (('' === $name) || isset($this->params[$name]) || isset($this->implementors[$name])) return; |
|
| 81 | + if (('' === $name) || isset($this->params[$name]) || isset($this->implementors[$name])) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 76 | 84 | |
| 77 | 85 | $this->implementors[$name] = $callback; |
| 78 | 86 | } |
@@ -141,14 +149,18 @@ discard block |
||
| 141 | 149 | |
| 142 | 150 | if ($process_id) { |
| 143 | 151 | |
| 144 | - if (isset($data['id'])) $result['id'] = $this->id->cast($data['id']); |
|
| 152 | + if (isset($data['id'])) { |
|
| 153 | + $result['id'] = $this->id->cast($data['id']); |
|
| 154 | + } |
|
| 145 | 155 | } |
| 146 | 156 | |
| 147 | 157 | # Cast params |
| 148 | 158 | |
| 149 | 159 | foreach ($this->params as $name => $param) { |
| 150 | 160 | |
| 151 | - if (isset($data[$name])) $result[$name] = $param->cast($data[$name]); |
|
| 161 | + if (isset($data[$name])) { |
|
| 162 | + $result[$name] = $param->cast($data[$name]); |
|
| 163 | + } |
|
| 152 | 164 | } |
| 153 | 165 | |
| 154 | 166 | # ------------------------ |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | |
| 42 | 42 | # Reset data |
| 43 | 43 | |
| 44 | - $this->id = 0; $this->data = $this->definition->implement(); |
|
| 44 | + $this->id = 0; $this->data = $this->definition->implement(); |
|
| 45 | 45 | |
| 46 | 46 | # Reset path |
| 47 | 47 | |
@@ -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 data |
| 43 | 55 | |
@@ -45,7 +57,9 @@ discard block |
||
| 45 | 57 | |
| 46 | 58 | # Reset path |
| 47 | 59 | |
| 48 | - if (static::$nesting) $this->data['path'] = []; |
|
| 60 | + if (static::$nesting) { |
|
| 61 | + $this->data['path'] = []; |
|
| 62 | + } |
|
| 49 | 63 | |
| 50 | 64 | # Implement entity |
| 51 | 65 | |
@@ -12,19 +12,27 @@ |
||
| 12 | 12 | |
| 13 | 13 | public function fill(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->definition->implement($data, true); |
| 18 | 20 | |
| 19 | - if (!($set['id'] > 0)) return false; |
|
| 21 | + if (!($set['id'] > 0)) { |
|
| 22 | + return false; |
|
| 23 | + } |
|
| 20 | 24 | |
| 21 | 25 | # Re-init entity |
| 22 | 26 | |
| 23 | 27 | $this->error = false; $this->id = $set['id']; |
| 24 | 28 | |
| 25 | - foreach ($set as $name => $value) if ($name !== 'id') $this->data[$name] = $value; |
|
| 29 | + foreach ($set as $name => $value) { |
|
| 30 | + if ($name !== 'id') $this->data[$name] = $value; |
|
| 31 | + } |
|
| 26 | 32 | |
| 27 | - if (static::$nesting) $this->data['path'] = $this->getPath(); |
|
| 33 | + if (static::$nesting) { |
|
| 34 | + $this->data['path'] = $this->getPath(); |
|
| 35 | + } |
|
| 28 | 36 | |
| 29 | 37 | # Implement entity |
| 30 | 38 | |
@@ -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 | |
@@ -40,7 +46,9 @@ discard block |
||
| 40 | 46 | |
| 41 | 47 | # Init path |
| 42 | 48 | |
| 43 | - if (static::$nesting) $this->data['path'] = $this->getPath(); |
|
| 49 | + if (static::$nesting) { |
|
| 50 | + $this->data['path'] = $this->getPath(); |
|
| 51 | + } |
|
| 44 | 52 | |
| 45 | 53 | # Implement entity |
| 46 | 54 | |