@@ -35,7 +35,8 @@ |
||
| 35 | 35 | if (property_exists($this, $prop_name) === true) { |
| 36 | 36 | { |
| 37 | 37 | $this->$prop_name = $value; |
| 38 | + } else { |
|
| 39 | + parent::set($prop_name, $value); |
|
| 38 | 40 | } |
| 39 | - else parent::set($prop_name, $value); |
|
| 40 | 41 | } |
| 41 | 42 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | public function import($assoc_data) |
| 45 | 45 | { |
| 46 | 46 | if (!is_array($assoc_data)) { |
| 47 | - throw new \Exception(__FUNCTION__ . '(assoc_data) parm is not an array'); |
|
| 47 | + throw new \Exception(__FUNCTION__.'(assoc_data) parm is not an array'); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // shove it all up in model, god will sort them out |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | if ($table_name === false) { |
| 73 | 73 | $calling_class = $reflect->getShortName(); |
| 74 | - if (defined($const_name = 'TABLE_' . strtoupper($calling_class))) { |
|
| 74 | + if (defined($const_name = 'TABLE_'.strtoupper($calling_class))) { |
|
| 75 | 75 | $table_name = constant($const_name); |
| 76 | 76 | } else { |
| 77 | 77 | $table_name = strtolower($calling_class); |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | { |
| 147 | 147 | $datass = []; |
| 148 | 148 | |
| 149 | - if(!is_null($arg2)) |
|
| 149 | + if (!is_null($arg2)) |
|
| 150 | 150 | $datass = [$arg1 => $arg2]; |
| 151 | - elseif(!is_array($arg1) && count(get_called_class()::table()->primaryKeys()) === 1){ |
|
| 151 | + elseif (!is_array($arg1) && count(get_called_class()::table()->primaryKeys()) === 1) { |
|
| 152 | 152 | $datass = [current(get_called_class()::table()->primaryKeys())->name() => $arg1]; |
| 153 | 153 | } |
| 154 | - elseif(is_array($arg1)){ |
|
| 154 | + elseif (is_array($arg1)) { |
|
| 155 | 155 | $datass = $arg1; |
| 156 | 156 | } |
| 157 | - else{ |
|
| 157 | + else { |
|
| 158 | 158 | throw new CruditesException('ARGUMENTS_ARE_NOT_ACTIONNABLE'); |
| 159 | 159 | } |
| 160 | 160 | |
@@ -146,15 +146,13 @@ |
||
| 146 | 146 | { |
| 147 | 147 | $datass = []; |
| 148 | 148 | |
| 149 | - if(!is_null($arg2)) |
|
| 150 | - $datass = [$arg1 => $arg2]; |
|
| 151 | - elseif(!is_array($arg1) && count(get_called_class()::table()->primaryKeys()) === 1){ |
|
| 149 | + if(!is_null($arg2)) { |
|
| 150 | + $datass = [$arg1 => $arg2]; |
|
| 151 | + } elseif(!is_array($arg1) && count(get_called_class()::table()->primaryKeys()) === 1){ |
|
| 152 | 152 | $datass = [current(get_called_class()::table()->primaryKeys())->name() => $arg1]; |
| 153 | - } |
|
| 154 | - elseif(is_array($arg1)){ |
|
| 153 | + } elseif(is_array($arg1)){ |
|
| 155 | 154 | $datass = $arg1; |
| 156 | - } |
|
| 157 | - else{ |
|
| 155 | + } else{ |
|
| 158 | 156 | throw new CruditesException('ARGUMENTS_ARE_NOT_ACTIONNABLE'); |
| 159 | 157 | } |
| 160 | 158 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function __toString() |
| 14 | 14 | { |
| 15 | - return static::class_short_name() . ' #' . $this->getId(); |
|
| 15 | + return static::class_short_name().' #'.$this->getId(); |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | public function immortal(): bool |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | // errors detection befire saving |
| 68 | 68 | $errors = []; |
| 69 | - if(empty($errors = $this->traitor('before_save'))) |
|
| 69 | + if (empty($errors = $this->traitor('before_save'))) |
|
| 70 | 70 | { |
| 71 | - if(empty($errors = $this->before_save())) |
|
| 71 | + if (empty($errors = $this->before_save())) |
|
| 72 | 72 | { |
| 73 | 73 | $errors = $this->validate(); |
| 74 | 74 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | if (!empty($persistence_errors = $table_row->persist())) { // validate and persist |
| 86 | 86 | $errors = []; |
| 87 | 87 | foreach ($persistence_errors as $column_name => $err) { |
| 88 | - $errors[sprintf('MODEL_%s_FIELD_%s', static::model_type(), $column_name)] = 'CRUDITES_' . $err; |
|
| 88 | + $errors[sprintf('MODEL_%s_FIELD_%s', static::model_type(), $column_name)] = 'CRUDITES_'.$err; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | return $errors; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | public static function tableAlias(): string |
| 161 | 161 | { |
| 162 | - if (defined(get_called_class() . '::TABLE_ALIAS')) { |
|
| 162 | + if (defined(get_called_class().'::TABLE_ALIAS')) { |
|
| 163 | 163 | return get_called_class()::TABLE_ALIAS; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | public static function model_type(): string |
| 170 | 170 | { |
| 171 | - if (defined(get_called_class() . '::MODEL_TYPE')) { |
|
| 171 | + if (defined(get_called_class().'::MODEL_TYPE')) { |
|
| 172 | 172 | return get_called_class()::MODEL_TYPE; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -73,8 +73,9 @@ |
||
| 73 | 73 | $errors = $this->validate(); |
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | - if (!empty($errors)) |
|
| 77 | - return $errors; |
|
| 76 | + if (!empty($errors)) { |
|
| 77 | + return $errors; |
|
| 78 | + } |
|
| 78 | 79 | |
| 79 | 80 | |
| 80 | 81 | // a tight model *always* match a single table row |