@@ -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 |
@@ -5,10 +5,10 @@ |
||
5 | 5 | use HnrAzevedo\Datamanager\Datamanager; |
6 | 6 | |
7 | 7 | /** |
8 | - * @property string $name |
|
9 | - * @property string $email |
|
10 | - * @property string $password |
|
11 | - */ |
|
8 | + * @property string $name |
|
9 | + * @property string $email |
|
10 | + * @property string $password |
|
11 | + */ |
|
12 | 12 | class User extends Datamanager{ |
13 | 13 | |
14 | 14 | public function __construct() |
@@ -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 |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | $stmt = Connect::getInstance()->prepare("{$query}"); |
34 | 34 | $stmt->execute($data); |
35 | 35 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
36 | - }catch(Exception $exception){ |
|
36 | + } catch(Exception $exception){ |
|
37 | 37 | $this->fail = $exception; |
38 | 38 | } |
39 | 39 | return []; |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $stmt = Connect::getInstance()->prepare("DESCRIBE {$this->table}"); |
46 | 46 | $stmt->execute(); |
47 | 47 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
48 | - }catch(Exception $exception){ |
|
48 | + } catch(Exception $exception){ |
|
49 | 49 | $this->fail = $exception; |
50 | 50 | return []; |
51 | 51 | } |
@@ -24,7 +24,7 @@ |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | if(!Connect::getInstance()->inTransaction()){ |
27 | - return Connect::getInstance()->beginTransaction(); |
|
27 | + return Connect::getInstance()->beginTransaction(); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | switch ($transaction) { |
@@ -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 | /* OR */ |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | |
44 | 44 | /* Remove by cause *Where* */ |
45 | 45 | $user->remove()->where([ |
46 | - ['name','=','Other Name'], |
|
47 | - 'OR' => ['email','LIKE','[email protected]'] |
|
46 | + ['name', '=', 'Other Name'], |
|
47 | + 'OR' => ['email', 'LIKE', '[email protected]'] |
|
48 | 48 | ])->execute(); |
49 | -}catch(Exception $er){ |
|
49 | +} catch (Exception $er) { |
|
50 | 50 | |
51 | 51 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
52 | 52 |
@@ -46,7 +46,7 @@ |
||
46 | 46 | ['name','=','Other Name'], |
47 | 47 | 'OR' => ['email','LIKE','[email protected]'] |
48 | 48 | ])->execute(); |
49 | -}catch(Exception $er){ |
|
49 | +} catch(Exception $er){ |
|
50 | 50 | |
51 | 51 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
52 | 52 |
@@ -137,7 +137,7 @@ |
||
137 | 137 | $this->check_fail(); |
138 | 138 | |
139 | 139 | $this->transaction('commit'); |
140 | - }catch(Exception $er){ |
|
140 | + } catch(Exception $er){ |
|
141 | 141 | $this->transaction('rollback'); |
142 | 142 | throw $er; |
143 | 143 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | { |
9 | 9 | use DataTrait; |
10 | 10 | |
11 | - private array $where = [''=> ["1",'=',"1"] ]; |
|
11 | + private array $where = [''=> ["1", '=', "1"]]; |
|
12 | 12 | |
13 | 13 | private function mountTable_Field(string $field, $value = null) |
14 | 14 | { |
@@ -20,16 +20,16 @@ discard block |
||
20 | 20 | $type = $value; |
21 | 21 | $maxlength = null; |
22 | 22 | |
23 | - if(strpos($value,'(')){ |
|
24 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['varchar','char','text'])) ? 'string' : $type; |
|
25 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['tinyint','mediumint','smallint','bigtint','int'])) ? 'int' : $type; |
|
26 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['decimal','float','double','real'])) ? 'float' : $type; |
|
23 | + if (strpos($value, '(')) { |
|
24 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['varchar', 'char', 'text'])) ? 'string' : $type; |
|
25 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['tinyint', 'mediumint', 'smallint', 'bigtint', 'int'])) ? 'int' : $type; |
|
26 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['decimal', 'float', 'double', 'real'])) ? 'float' : $type; |
|
27 | 27 | } |
28 | 28 | |
29 | - $maxlength = (in_array( $type , ['string','float','int'])) ? substr($value,(strpos($value,'(')+1),-1) : $maxlength; |
|
30 | - $maxlength = (in_array( $type , ['date'])) ? 10 : $maxlength; |
|
31 | - $maxlength = (in_array( $type , ['datetime'])) ? 19 : $maxlength; |
|
32 | - $maxlength = (in_array( $type , ['boolean'])) ? 1 : $maxlength; |
|
29 | + $maxlength = (in_array($type, ['string', 'float', 'int'])) ? substr($value, (strpos($value, '(') + 1), -1) : $maxlength; |
|
30 | + $maxlength = (in_array($type, ['date'])) ? 10 : $maxlength; |
|
31 | + $maxlength = (in_array($type, ['datetime'])) ? 19 : $maxlength; |
|
32 | + $maxlength = (in_array($type, ['boolean'])) ? 1 : $maxlength; |
|
33 | 33 | |
34 | 34 | $this->$field = ['maxlength' => $maxlength]; |
35 | 35 | $this->$field = ['type' => $type]; |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | |
73 | 73 | public function check_where_array(array $where) |
74 | 74 | { |
75 | - if(count($where) != 3){ |
|
76 | - throw new Exception("Condition where set incorrectly: ".implode(' ',$where)); |
|
75 | + if (count($where) != 3) { |
|
76 | + throw new Exception("Condition where set incorrectly: ".implode(' ', $where)); |
|
77 | 77 | } |
78 | 78 | |
79 | - if(!array_key_exists($where[0],$this->data) && $this->full){ |
|
79 | + if (!array_key_exists($where[0], $this->data) && $this->full) { |
|
80 | 80 | throw new Exception("{$where[0]} field does not exist in the table {$this->table}."); |
81 | 81 | } |
82 | 82 | } |
@@ -84,14 +84,14 @@ discard block |
||
84 | 84 | private function mountRemove(): array |
85 | 85 | { |
86 | 86 | $return = ['data' => [], 'where' => '']; |
87 | - foreach($this->where as $clause => $condition){ |
|
88 | - if(strlen($clause) === 0){ |
|
87 | + foreach ($this->where as $clause => $condition) { |
|
88 | + if (strlen($clause) === 0) { |
|
89 | 89 | $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]} "; |
90 | 90 | $return['data'] .= "q_{$condition[0]}={$condition[2]}&"; |
91 | 91 | continue; |
92 | 92 | } |
93 | 93 | |
94 | - foreach($condition as $value){ |
|
94 | + foreach ($condition as $value) { |
|
95 | 95 | $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]} "; |
96 | 96 | $return['data'] .= "q_{$value[0]}={$value[2]}&"; |
97 | 97 | } |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | $return = ['data' => []]; |
105 | 105 | |
106 | 106 | foreach ($this->data as $key => $value) { |
107 | - if(strstr($this->data[$key]['extra'],'auto_increment') && $key !== $this->primary){ |
|
107 | + if (strstr($this->data[$key]['extra'], 'auto_increment') && $key !== $this->primary) { |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | |
111 | - if(($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key){ |
|
111 | + if (($this->data[$key]['changed'] && $this->data[$key]['upgradeable']) || $this->primary === $key) { |
|
112 | 112 | $return['data'][$key] = $this->data[$key]['value']; |
113 | 113 | } |
114 | 114 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | $this->transaction('begin'); |
122 | 122 | |
123 | - try{ |
|
123 | + try { |
|
124 | 124 | $this->update( |
125 | 125 | $this->mountSave()['data'], |
126 | 126 | "{$this->primary}=:{$this->primary}", |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $this->check_fail(); |
131 | 131 | |
132 | 132 | $this->transaction('commit'); |
133 | - }catch(Exception $er){ |
|
133 | + } catch (Exception $er) { |
|
134 | 134 | $this->transaction('rollback'); |
135 | 135 | throw $er; |
136 | 136 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | $key = (!$key) ? '' : " {$key} "; |
148 | 148 | |
149 | - if(is_array($value[0])){ |
|
149 | + if (is_array($value[0])) { |
|
150 | 150 | |
151 | 151 | foreach ($value as $k => $v) { |
152 | 152 | $return['where'] .= " {$key} {$v[0]} {$v[1]} :q_{$v[0]} "; |
@@ -165,21 +165,21 @@ discard block |
||
165 | 165 | |
166 | 166 | private function mountSelect() |
167 | 167 | { |
168 | - $select = implode(',',array_keys($this->select)); |
|
168 | + $select = implode(',', array_keys($this->select)); |
|
169 | 169 | |
170 | - $this->query = str_replace('*', $select,$this->query); |
|
170 | + $this->query = str_replace('*', $select, $this->query); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | private function mountLimit() |
174 | 174 | { |
175 | - if(!is_null($this->limit)){ |
|
175 | + if (!is_null($this->limit)) { |
|
176 | 176 | $this->query .= " LIMIT {$this->limit}"; |
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
180 | 180 | private function mountOffset() |
181 | 181 | { |
182 | - if(!is_null($this->offset)){ |
|
182 | + if (!is_null($this->offset)) { |
|
183 | 183 | $this->query .= " OFFSET {$this->offset}"; |
184 | 184 | } |
185 | 185 | } |
@@ -266,7 +266,7 @@ |
||
266 | 266 | |
267 | 267 | $this->transaction('commit'); |
268 | 268 | |
269 | - }catch(Exception $er){ |
|
269 | + } catch(Exception $er){ |
|
270 | 270 | $this->transaction('rollback'); |
271 | 271 | throw $er; |
272 | 272 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -trait DataTrait{ |
|
7 | +trait DataTrait { |
|
8 | 8 | use CrudTrait; |
9 | 9 | |
10 | 10 | protected ?string $table = null; |
@@ -36,16 +36,16 @@ discard block |
||
36 | 36 | return $this; |
37 | 37 | } |
38 | 38 | |
39 | - public function __set(string $prop,$value) |
|
39 | + public function __set(string $prop, $value) |
|
40 | 40 | { |
41 | 41 | |
42 | - if(is_array($value)){ |
|
42 | + if (is_array($value)) { |
|
43 | 43 | $attr = array_keys($value)[0]; |
44 | 44 | $this->data[$prop][$attr] = $value[$attr]; |
45 | 45 | return $this; |
46 | 46 | } |
47 | 47 | |
48 | - if($this->full && !array_key_exists($prop,$this->data)){ |
|
48 | + if ($this->full && !array_key_exists($prop, $this->data)) { |
|
49 | 49 | throw new Exception("{$prop} field does not exist in the table {$this->table}."); |
50 | 50 | } |
51 | 51 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | public function __get(string $field) |
64 | 64 | { |
65 | - if($this->full && !array_key_exists($field,$this->data)){ |
|
65 | + if ($this->full && !array_key_exists($field, $this->data)) { |
|
66 | 66 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
67 | 67 | } |
68 | 68 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $deniable = (is_array($deniable)) ? $deniable : [$deniable]; |
80 | 80 | |
81 | 81 | foreach ($deniable as $field) { |
82 | - if(!array_key_exists($field,$this->data)){ |
|
82 | + if (!array_key_exists($field, $this->data)) { |
|
83 | 83 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
84 | 84 | } |
85 | 85 | |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | |
100 | 100 | public function orderBy(string $field, string $ord = 'ASC') |
101 | 101 | { |
102 | - if(!array_key_exists(str_replace(['asc','ASC','desc','DESC',' '],'',$field),$this->data) && $this->full){ |
|
102 | + if (!array_key_exists(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field), $this->data) && $this->full) { |
|
103 | 103 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
104 | 104 | } |
105 | 105 | |
106 | - if(strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')){ |
|
106 | + if (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) { |
|
107 | 107 | $ord = ''; |
108 | 108 | } |
109 | 109 | |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | |
119 | 119 | foreach ($params as $field) { |
120 | 120 | |
121 | - if(!array_key_exists($field,$this->data) && $this->full){ |
|
121 | + if (!array_key_exists($field, $this->data) && $this->full) { |
|
122 | 122 | throw new Exception("{$field} field does not exist in the table {$this->table}."); |
123 | 123 | } |
124 | 124 | |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | |
132 | 132 | public function where(array $where) |
133 | 133 | { |
134 | - $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? ''; |
|
134 | + $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? ''; |
|
135 | 135 | $w = []; |
136 | 136 | foreach ($where as $condition => $values) { |
137 | 137 | |
138 | - if(!is_array($values)){ |
|
138 | + if (!is_array($values)) { |
|
139 | 139 | $w['AND'][] = $values; |
140 | 140 | continue; |
141 | 141 | } |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | |
147 | 147 | } |
148 | 148 | |
149 | - $this->where = array_merge($this->where,$w); |
|
149 | + $this->where = array_merge($this->where, $w); |
|
150 | 150 | |
151 | 151 | return $this; |
152 | 152 | } |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | |
160 | 160 | public function offset(int $offset) |
161 | 161 | { |
162 | - if(is_null($this->limit)){ |
|
162 | + if (is_null($this->limit)) { |
|
163 | 163 | throw new Exception("The limit must be set before the offset."); |
164 | 164 | } |
165 | 165 | |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | foreach ($arrayValues as $key => $value) { |
191 | 191 | |
192 | - if(!array_key_exists($key,$this->data)){ |
|
192 | + if (!array_key_exists($key, $this->data)) { |
|
193 | 193 | throw new Exception("{$key} field does not exist in the table {$this->table}."); |
194 | 194 | } |
195 | 195 | |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | $string = ''; |
204 | 204 | foreach ($this->data as $key => $value) { |
205 | 205 | |
206 | - if(gettype($value)==='object'){ |
|
206 | + if (gettype($value) === 'object') { |
|
207 | 207 | $value = $value->getData()[$this->primary]['value']; |
208 | 208 | } |
209 | 209 | |
@@ -214,19 +214,19 @@ discard block |
||
214 | 214 | |
215 | 215 | public function remove(?bool $exec = false) |
216 | 216 | { |
217 | - if(!$exec){ |
|
217 | + if (!$exec) { |
|
218 | 218 | $this->clause = 'remove'; |
219 | 219 | return $this; |
220 | 220 | } |
221 | 221 | |
222 | 222 | $this->clause = null; |
223 | 223 | |
224 | - if(count($this->where) == 1){ |
|
224 | + if (count($this->where) == 1) { |
|
225 | 225 | $this->removeById(); |
226 | 226 | return $this; |
227 | 227 | } |
228 | 228 | |
229 | - $this->delete($this->mountRemove()['where'], substr( $this->mountRemove()['data'] ,0,-1) ); |
|
229 | + $this->delete($this->mountRemove()['where'], substr($this->mountRemove()['data'], 0, -1)); |
|
230 | 230 | |
231 | 231 | $this->check_fail(); |
232 | 232 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | |
236 | 236 | private function removeById(): bool |
237 | 237 | { |
238 | - $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
238 | + $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
239 | 239 | |
240 | 240 | $this->check_fail(); |
241 | 241 | |
@@ -249,11 +249,11 @@ discard block |
||
249 | 249 | $data = []; |
250 | 250 | |
251 | 251 | foreach ($this->data as $key => $value) { |
252 | - if(strstr($this->data[$key]['extra'],'auto_increment')){ |
|
252 | + if (strstr($this->data[$key]['extra'], 'auto_increment')) { |
|
253 | 253 | continue; |
254 | 254 | } |
255 | 255 | |
256 | - if(strlen($value['value']) > $value['maxlength']){ |
|
256 | + if (strlen($value['value']) > $value['maxlength']) { |
|
257 | 257 | throw new Exception("The information provided for column {$key} of table {$this->table} exceeded that allowed."); |
258 | 258 | } |
259 | 259 | |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | $this->transaction('begin'); |
266 | - try{ |
|
266 | + try { |
|
267 | 267 | |
268 | 268 | $id = $this->insert($data); |
269 | 269 | |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | |
274 | 274 | $this->transaction('commit'); |
275 | 275 | |
276 | - }catch(Exception $er){ |
|
276 | + } catch (Exception $er) { |
|
277 | 277 | $this->transaction('rollback'); |
278 | 278 | throw $er; |
279 | 279 | } |
@@ -283,13 +283,13 @@ discard block |
||
283 | 283 | |
284 | 284 | public function toEntity() |
285 | 285 | { |
286 | - if($this->getCount() === 0){ |
|
286 | + if ($this->getCount() === 0) { |
|
287 | 287 | return null; |
288 | 288 | } |
289 | 289 | |
290 | 290 | $entity = $this->setByDatabase($this->result[0]); |
291 | 291 | |
292 | - if(count($this->result) > 1){ |
|
292 | + if (count($this->result) > 1) { |
|
293 | 293 | $entity = []; |
294 | 294 | foreach ($this->result as $key => $value) { |
295 | 295 | $entity[] = $this->setByDatabase($value); |
@@ -301,13 +301,13 @@ discard block |
||
301 | 301 | |
302 | 302 | public function findById($id) |
303 | 303 | { |
304 | - $this->where([$this->primary,'=',$id]); |
|
304 | + $this->where([$this->primary, '=', $id]); |
|
305 | 305 | return $this; |
306 | 306 | } |
307 | 307 | |
308 | 308 | public function execute() |
309 | 309 | { |
310 | - if(!is_null($this->clause) && $this->clause == 'remove'){ |
|
310 | + if (!is_null($this->clause) && $this->clause == 'remove') { |
|
311 | 311 | return $this->remove(true); |
312 | 312 | } |
313 | 313 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | |
316 | 316 | $this->mountSelect(); |
317 | 317 | |
318 | - $where = substr($this->mountWhereExec()['where'],0,-1); |
|
318 | + $where = substr($this->mountWhereExec()['where'], 0, -1); |
|
319 | 319 | $this->query .= " WHERE {$where} "; |
320 | 320 | |
321 | 321 | $this->query .= $this->order; |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | { |
338 | 338 | $this->query = " SELECT * FROM {$this->table} "; |
339 | 339 | |
340 | - if(is_int($key)){ |
|
340 | + if (is_int($key)) { |
|
341 | 341 | return $this->findById($key); |
342 | 342 | } |
343 | 343 |