@@ -14,12 +14,12 @@ discard block |
||
| 14 | 14 | if (empty(self::$instance)) { |
| 15 | 15 | try { |
| 16 | 16 | |
| 17 | - if(!defined('DATAMANAGER_CONFIG')){ |
|
| 17 | + if (!defined('DATAMANAGER_CONFIG')) { |
|
| 18 | 18 | throw new Exception("Information for connection to the database not defined."); |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | self::$instance = new PDO( |
| 22 | - DATAMANAGER_CONFIG['driver'] . ':host='.DATAMANAGER_CONFIG['host'] . ';port='.DATAMANAGER_CONFIG['port'] . ';dbname='.DATAMANAGER_CONFIG['database'] . ';charset='.DATAMANAGER_CONFIG['charset'], |
|
| 22 | + DATAMANAGER_CONFIG['driver'].':host='.DATAMANAGER_CONFIG['host'].';port='.DATAMANAGER_CONFIG['port'].';dbname='.DATAMANAGER_CONFIG['database'].';charset='.DATAMANAGER_CONFIG['charset'], |
|
| 23 | 23 | DATAMANAGER_CONFIG['username'], |
| 24 | 24 | DATAMANAGER_CONFIG['password'], |
| 25 | 25 | DATAMANAGER_CONFIG['options'] |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | return self::$instance; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - public static function destroy(){ |
|
| 34 | + public static function destroy() { |
|
| 35 | 35 | self::$instance = null; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -9,11 +9,11 @@ |
||
| 9 | 9 | * @property string $email |
| 10 | 10 | * @property string $password |
| 11 | 11 | */ |
| 12 | -class User extends Datamanager{ |
|
| 12 | +class User extends Datamanager { |
|
| 13 | 13 | |
| 14 | 14 | public function __construct() |
| 15 | 15 | { |
| 16 | - parent::create('user','id'); |
|
| 16 | + parent::create('user', 'id'); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | } |
| 20 | 20 | \ No newline at end of file |
@@ -6,24 +6,24 @@ discard block |
||
| 6 | 6 | use PDOException; |
| 7 | 7 | use PDO; |
| 8 | 8 | |
| 9 | -trait CrudTrait{ |
|
| 9 | +trait CrudTrait { |
|
| 10 | 10 | |
| 11 | 11 | protected ?Exception $fail = null; |
| 12 | 12 | |
| 13 | 13 | protected function check_fail() |
| 14 | 14 | { |
| 15 | - if(!is_null($this->fail)){ |
|
| 15 | + if (!is_null($this->fail)) { |
|
| 16 | 16 | throw $this->fail; |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | protected function transaction(string $transaction): ?bool |
| 21 | 21 | { |
| 22 | - if(array_key_exists($transaction,['begin','commit','rollback'])){ |
|
| 22 | + if (array_key_exists($transaction, ['begin', 'commit', 'rollback'])) { |
|
| 23 | 23 | throw new Exception("{$transaction} é um estado inválido para transações."); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | - if(!Connect::getInstance()->inTransaction()){ |
|
| 26 | + if (!Connect::getInstance()->inTransaction()) { |
|
| 27 | 27 | return Connect::getInstance()->beginTransaction(); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -34,13 +34,13 @@ discard block |
||
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | - protected function select(string $query,array $data): ?array |
|
| 37 | + protected function select(string $query, array $data): ?array |
|
| 38 | 38 | { |
| 39 | - try{ |
|
| 39 | + try { |
|
| 40 | 40 | $stmt = Connect::getInstance()->prepare("{$query}"); |
| 41 | 41 | $stmt->execute($data); |
| 42 | 42 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 43 | - }catch(Exception $exception){ |
|
| 43 | + } catch (Exception $exception) { |
|
| 44 | 44 | $this->fail = $exception; |
| 45 | 45 | } |
| 46 | 46 | return []; |
@@ -48,11 +48,11 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | protected function describe(): array |
| 50 | 50 | { |
| 51 | - try{ |
|
| 51 | + try { |
|
| 52 | 52 | $stmt = Connect::getInstance()->prepare("DESCRIBE {$this->table}"); |
| 53 | 53 | $stmt->execute(); |
| 54 | 54 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
| 55 | - }catch(Exception $exception){ |
|
| 55 | + } catch (Exception $exception) { |
|
| 56 | 56 | $this->fail = $exception; |
| 57 | 57 | return []; |
| 58 | 58 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | try { |
| 64 | 64 | $columns = implode(", ", array_keys($data)); |
| 65 | - $values = ":" . implode(", :", array_keys($data)); |
|
| 65 | + $values = ":".implode(", :", array_keys($data)); |
|
| 66 | 66 | |
| 67 | 67 | $stmt = Connect::getInstance()->prepare("INSERT INTO {$this->table} ({$columns}) VALUES ({$values})"); |
| 68 | 68 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | try { |
| 101 | 101 | $stmt = Connect::getInstance()->prepare("DELETE FROM {$this->table} WHERE {$terms}"); |
| 102 | 102 | |
| 103 | - if($params){ |
|
| 103 | + if ($params) { |
|
| 104 | 104 | parse_str($params, $arr); |
| 105 | 105 | $stmt->execute($arr); |
| 106 | 106 | return true; |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | |
| 11 | 11 | $entity = new User(); |
| 12 | 12 | |
| 13 | -try{ |
|
| 13 | +try { |
|
| 14 | 14 | /* Set new info for insert in database */ |
| 15 | 15 | $entity->name = 'Henri Azevedo'; |
| 16 | 16 | $entity->email = '[email protected]'; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | $user = $entity->find()->execute()->first()->toEntity(); |
| 24 | 24 | |
| 25 | 25 | /* Search only for columns defined in advance */ |
| 26 | - $user = $entity->find()->only(['name','email'])->execute()->first(); |
|
| 26 | + $user = $entity->find()->only(['name', 'email'])->execute()->first(); |
|
| 27 | 27 | $name = $user->name; |
| 28 | 28 | $email = $user->email; |
| 29 | 29 | |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | /* Remove by cause *Where* */ |
| 47 | 47 | $user->remove()->where([ |
| 48 | - ['name','=','Other Name'], |
|
| 49 | - 'OR' => ['email','LIKE','[email protected]'] |
|
| 48 | + ['name', '=', 'Other Name'], |
|
| 49 | + 'OR' => ['email', 'LIKE', '[email protected]'] |
|
| 50 | 50 | ])->execute(); |
| 51 | -}catch(Exception $er){ |
|
| 51 | +} catch (Exception $er) { |
|
| 52 | 52 | |
| 53 | 53 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 54 | 54 | |
@@ -4,36 +4,36 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -trait CheckTrait{ |
|
| 7 | +trait CheckTrait { |
|
| 8 | 8 | |
| 9 | 9 | protected function check_where_array(array $where) |
| 10 | 10 | { |
| 11 | - if(count($where) != 3){ |
|
| 12 | - throw new Exception("Condition where set incorrectly: ".implode(' ',$where)); |
|
| 11 | + if (count($where) != 3) { |
|
| 12 | + throw new Exception("Condition where set incorrectly: ".implode(' ', $where)); |
|
| 13 | 13 | } |
| 14 | 14 | |
| 15 | - if(!array_key_exists($where[0],$this->data) && $this->full){ |
|
| 15 | + if (!array_key_exists($where[0], $this->data) && $this->full) { |
|
| 16 | 16 | throw new Exception("{$where[0]} field does not exist in the table {$this->table}."); |
| 17 | 17 | } |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | 20 | protected function isSettable(string $prop) |
| 21 | 21 | { |
| 22 | - if($this->full && !array_key_exists($prop,$this->data)){ |
|
| 22 | + if ($this->full && !array_key_exists($prop, $this->data)) { |
|
| 23 | 23 | throw new Exception("{$prop} field does not exist in the table {$this->table}."); |
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | protected function checkLimit() |
| 28 | 28 | { |
| 29 | - if(is_null($this->limit)){ |
|
| 29 | + if (is_null($this->limit)) { |
|
| 30 | 30 | throw new Exception("The limit must be set before the offset."); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - protected function checkMaxlength(string $field, $val , $max) |
|
| 34 | + protected function checkMaxlength(string $field, $val, $max) |
|
| 35 | 35 | { |
| 36 | - if(strlen($val) > $max){ |
|
| 36 | + if (strlen($val) > $max) { |
|
| 37 | 37 | throw new Exception("The information provided for column {$field} of table {$this->table} exceeded that allowed."); |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | |
| 46 | 46 | protected function isIncremented(string $field): bool |
| 47 | 47 | { |
| 48 | - return ( strstr($this->data[$field]['extra'],'auto_increment') && $field !== $this->primary ); |
|
| 48 | + return (strstr($this->data[$field]['extra'], 'auto_increment') && $field !== $this->primary); |
|
| 49 | 49 | } |
| 50 | 50 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace HnrAzevedo\Datamanager; |
| 4 | 4 | |
| 5 | -trait DataTrait{ |
|
| 5 | +trait DataTrait { |
|
| 6 | 6 | use CrudTrait, CheckTrait; |
| 7 | 7 | |
| 8 | 8 | protected ?string $table = null; |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | protected function mountRemove(): array |
| 25 | 25 | { |
| 26 | 26 | $return = ['data' => '', 'where' => '']; |
| 27 | - foreach($this->where as $clause => $condition){ |
|
| 28 | - if(strlen($clause) === 0){ |
|
| 27 | + foreach ($this->where as $clause => $condition) { |
|
| 28 | + if (strlen($clause) === 0) { |
|
| 29 | 29 | $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]} "; |
| 30 | 30 | $return['data'] .= "q_{$condition[0]}={$condition[2]}&"; |
| 31 | 31 | continue; |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - foreach($condition as $value){ |
|
| 34 | + foreach ($condition as $value) { |
|
| 35 | 35 | $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]} "; |
| 36 | 36 | $return['data'] .= "q_{$value[0]}={$value[2]}&"; |
| 37 | 37 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $return = ['data' => []]; |
| 45 | 45 | |
| 46 | 46 | foreach ($this->data as $key => $value) { |
| 47 | - if($this->upgradeable($key) && !$this->isIncremented($key)){ |
|
| 47 | + if ($this->upgradeable($key) && !$this->isIncremented($key)) { |
|
| 48 | 48 | $return['data'][$key] = $this->data[$key]['value']; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $key = (!$key) ? '' : " {$key} "; |
| 62 | 62 | |
| 63 | - if(is_array($value[0])){ |
|
| 63 | + if (is_array($value[0])) { |
|
| 64 | 64 | |
| 65 | 65 | foreach ($value as $k => $v) { |
| 66 | 66 | $return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
@@ -79,21 +79,21 @@ discard block |
||
| 79 | 79 | |
| 80 | 80 | protected function mountSelect() |
| 81 | 81 | { |
| 82 | - $select = implode(',',array_keys($this->select)); |
|
| 82 | + $select = implode(',', array_keys($this->select)); |
|
| 83 | 83 | |
| 84 | - $this->query = str_replace('*', $select,$this->query); |
|
| 84 | + $this->query = str_replace('*', $select, $this->query); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | protected function mountLimit() |
| 88 | 88 | { |
| 89 | - if(!is_null($this->limit)){ |
|
| 89 | + if (!is_null($this->limit)) { |
|
| 90 | 90 | $this->query .= " LIMIT {$this->limit}"; |
| 91 | 91 | } |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | protected function mountOffset() |
| 95 | 95 | { |
| 96 | - if(!is_null($this->offset)){ |
|
| 96 | + if (!is_null($this->offset)) { |
|
| 97 | 97 | $this->query .= " OFFSET {$this->offset}"; |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace HnrAzevedo\Datamanager; |
| 4 | 4 | |
| 5 | -trait SynchronizeTrait{ |
|
| 5 | +trait SynchronizeTrait { |
|
| 6 | 6 | use CrudTrait; |
| 7 | 7 | |
| 8 | 8 | protected ?string $table = null; |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $type = $value; |
| 44 | 44 | |
| 45 | - if(strpos($value,'(')){ |
|
| 46 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['varchar','char','text'])) ? 'string' : $type; |
|
| 47 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['tinyint','mediumint','smallint','bigtint','int'])) ? 'int' : $type; |
|
| 48 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['decimal','float','double','real'])) ? 'float' : $type; |
|
| 45 | + if (strpos($value, '(')) { |
|
| 46 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['varchar', 'char', 'text'])) ? 'string' : $type; |
|
| 47 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['tinyint', 'mediumint', 'smallint', 'bigtint', 'int'])) ? 'int' : $type; |
|
| 48 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['decimal', 'float', 'double', 'real'])) ? 'float' : $type; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | $this->mountTable_Maxlength($field, $type, $value); |
@@ -54,10 +54,10 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | protected function mountTable_Maxlength(string $field, string $type, $default = null) |
| 56 | 56 | { |
| 57 | - $maxlength = (in_array( $type , ['string','float','int'])) ? substr($default,(strpos($default,'(')+1),-1) : 0; |
|
| 58 | - $maxlength = (in_array( $type , ['date'])) ? 10 : $maxlength; |
|
| 59 | - $maxlength = (in_array( $type , ['datetime'])) ? 19 : $maxlength; |
|
| 60 | - $maxlength = (in_array( $type , ['boolean'])) ? 1 : $maxlength; |
|
| 57 | + $maxlength = (in_array($type, ['string', 'float', 'int'])) ? substr($default, (strpos($default, '(') + 1), -1) : 0; |
|
| 58 | + $maxlength = (in_array($type, ['date'])) ? 10 : $maxlength; |
|
| 59 | + $maxlength = (in_array($type, ['datetime'])) ? 19 : $maxlength; |
|
| 60 | + $maxlength = (in_array($type, ['boolean'])) ? 1 : $maxlength; |
|
| 61 | 61 | $this->$field = ['maxlength' => $maxlength]; |
| 62 | 62 | } |
| 63 | 63 | |
@@ -11,12 +11,12 @@ discard block |
||
| 11 | 11 | protected ?string $table = null; |
| 12 | 12 | protected ?string $primary = null; |
| 13 | 13 | protected array $data = []; |
| 14 | - protected array $where = [''=> ["1",'=',"1"] ]; |
|
| 14 | + protected array $where = [''=> ["1", '=', "1"]]; |
|
| 15 | 15 | |
| 16 | - public function __set(string $prop,$value) |
|
| 16 | + public function __set(string $prop, $value) |
|
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - if(is_array($value)){ |
|
| 19 | + if (is_array($value)) { |
|
| 20 | 20 | $attr = array_keys($value)[0]; |
| 21 | 21 | $this->data[$prop][$attr] = $value[$attr]; |
| 22 | 22 | return $this; |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | $deniable = (is_array($deniable)) ? $deniable : [$deniable]; |
| 52 | 52 | |
| 53 | 53 | foreach ($deniable as $field) { |
| 54 | - if(!array_key_exists($field,$this->data)){ |
|
| 54 | + if (!array_key_exists($field, $this->data)) { |
|
| 55 | 55 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
| 56 | 56 | } |
| 57 | 57 | |
@@ -71,9 +71,9 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public function orderBy(string $field, string $ord = 'ASC') |
| 73 | 73 | { |
| 74 | - $this->isSettable( str_replace(['asc','ASC','desc','DESC',' '],'',$field) ); |
|
| 74 | + $this->isSettable(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field)); |
|
| 75 | 75 | |
| 76 | - $ord = (strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')) ? '' : $ord; |
|
| 76 | + $ord = (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) ? '' : $ord; |
|
| 77 | 77 | |
| 78 | 78 | $this->order = " ORDER BY {$field} {$ord} "; |
| 79 | 79 | return $this; |
@@ -97,11 +97,11 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | public function where(array $where) |
| 99 | 99 | { |
| 100 | - $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? ''; |
|
| 100 | + $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? ''; |
|
| 101 | 101 | $w = []; |
| 102 | 102 | foreach ($where as $condition => $values) { |
| 103 | 103 | |
| 104 | - if(!is_array($values)){ |
|
| 104 | + if (!is_array($values)) { |
|
| 105 | 105 | $w['AND'][] = $values; |
| 106 | 106 | continue; |
| 107 | 107 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - $this->where = array_merge($this->where,$w); |
|
| 115 | + $this->where = array_merge($this->where, $w); |
|
| 116 | 116 | |
| 117 | 117 | return $this; |
| 118 | 118 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $string = ''; |
| 167 | 167 | foreach ($this->data as $key => $value) { |
| 168 | 168 | |
| 169 | - if(gettype($value)==='object'){ |
|
| 169 | + if (gettype($value) === 'object') { |
|
| 170 | 170 | $value = $value->getData()[$this->primary]['value']; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -177,19 +177,19 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | public function remove(?bool $exec = false) |
| 179 | 179 | { |
| 180 | - if($exec !== null){ |
|
| 180 | + if ($exec !== null) { |
|
| 181 | 181 | $this->clause = 'remove'; |
| 182 | 182 | return $this; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | $this->clause = null; |
| 186 | 186 | |
| 187 | - if(count($this->where) == 1){ |
|
| 187 | + if (count($this->where) == 1) { |
|
| 188 | 188 | $this->removeById(); |
| 189 | 189 | return $this; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - $this->delete($this->mountRemove()['where'], substr( $this->mountRemove()['data'] ,0,-1) ); |
|
| 192 | + $this->delete($this->mountRemove()['where'], substr($this->mountRemove()['data'], 0, -1)); |
|
| 193 | 193 | |
| 194 | 194 | $this->check_fail(); |
| 195 | 195 | |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | |
| 199 | 199 | private function removeById(): bool |
| 200 | 200 | { |
| 201 | - $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
| 201 | + $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
| 202 | 202 | |
| 203 | 203 | $this->check_fail(); |
| 204 | 204 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | $data = []; |
| 213 | 213 | |
| 214 | 214 | foreach ($this->data as $key => $value) { |
| 215 | - if(strstr($this->data[$key]['extra'],'auto_increment')){ |
|
| 215 | + if (strstr($this->data[$key]['extra'], 'auto_increment')) { |
|
| 216 | 216 | continue; |
| 217 | 217 | } |
| 218 | 218 | |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | $this->transaction('begin'); |
| 227 | - try{ |
|
| 227 | + try { |
|
| 228 | 228 | |
| 229 | 229 | $id = $this->insert($data); |
| 230 | 230 | |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | $this->transaction('commit'); |
| 236 | 236 | |
| 237 | - }catch(Exception $er){ |
|
| 237 | + } catch (Exception $er) { |
|
| 238 | 238 | $this->transaction('rollback'); |
| 239 | 239 | throw $er; |
| 240 | 240 | } |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | |
| 245 | 245 | public function toEntity() |
| 246 | 246 | { |
| 247 | - if($this->getCount() === 0){ |
|
| 247 | + if ($this->getCount() === 0) { |
|
| 248 | 248 | return null; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $entity = $this->setByDatabase($this->result[0]); |
| 252 | 252 | |
| 253 | - if(count($this->result) > 1){ |
|
| 253 | + if (count($this->result) > 1) { |
|
| 254 | 254 | $entity = []; |
| 255 | 255 | foreach ($this->result as $key => $value) { |
| 256 | 256 | $entity[] = $this->setByDatabase($value); |
@@ -262,12 +262,12 @@ discard block |
||
| 262 | 262 | |
| 263 | 263 | public function findById($id) |
| 264 | 264 | { |
| 265 | - return $this->where([$this->primary,'=',$id]); |
|
| 265 | + return $this->where([$this->primary, '=', $id]); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | public function execute() |
| 269 | 269 | { |
| 270 | - if(!is_null($this->clause) && $this->clause == 'remove'){ |
|
| 270 | + if (!is_null($this->clause) && $this->clause == 'remove') { |
|
| 271 | 271 | return $this->remove(true); |
| 272 | 272 | } |
| 273 | 273 | |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | $this->mountSelect(); |
| 277 | 277 | |
| 278 | - $where = substr($this->mountWhereExec()['where'],0,-1); |
|
| 278 | + $where = substr($this->mountWhereExec()['where'], 0, -1); |
|
| 279 | 279 | $this->query .= " WHERE {$where} "; |
| 280 | 280 | |
| 281 | 281 | $this->query .= $this->order; |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | { |
| 304 | 304 | $this->transaction('begin'); |
| 305 | 305 | |
| 306 | - try{ |
|
| 306 | + try { |
|
| 307 | 307 | $this->update( |
| 308 | 308 | $this->mountSave()['data'], |
| 309 | 309 | "{$this->primary}=:{$this->primary}", |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | $this->check_fail(); |
| 314 | 314 | |
| 315 | 315 | $this->transaction('commit'); |
| 316 | - }catch(Exception $er){ |
|
| 316 | + } catch (Exception $er) { |
|
| 317 | 317 | $this->transaction('rollback'); |
| 318 | 318 | throw $er; |
| 319 | 319 | } |