@@ -11,7 +11,7 @@ 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 | protected array $between = []; |
16 | 16 | |
17 | 17 | public function getData(): ?array |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $deniable = (is_array($deniable)) ? $deniable : [$deniable]; |
30 | 30 | |
31 | 31 | foreach ($deniable as $field) { |
32 | - if(!array_key_exists($field,$this->data)){ |
|
32 | + if (!array_key_exists($field, $this->data)) { |
|
33 | 33 | throw new DatamanagerException("{$field} field does not exist in the table {$this->table}."); |
34 | 34 | } |
35 | 35 | $this->excepts[$field] = true; |
@@ -48,9 +48,9 @@ discard block |
||
48 | 48 | |
49 | 49 | public function orderBy(string $field, string $ord = 'ASC') |
50 | 50 | { |
51 | - $this->isSettable( str_replace(['asc','ASC','desc','DESC',' '],'',$field) ); |
|
51 | + $this->isSettable(str_replace(['asc', 'ASC', 'desc', 'DESC', ' '], '', $field)); |
|
52 | 52 | |
53 | - $ord = (strpos(strtolower($field),'asc') || strpos(strtolower($field),'desc')) ? '' : $ord; |
|
53 | + $ord = (strpos(strtolower($field), 'asc') || strpos(strtolower($field), 'desc')) ? '' : $ord; |
|
54 | 54 | |
55 | 55 | $this->order = " ORDER BY {$field} {$ord} "; |
56 | 56 | return $this; |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | |
73 | 73 | public function where(array $where) |
74 | 74 | { |
75 | - $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? ''; |
|
75 | + $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? ''; |
|
76 | 76 | $w = []; |
77 | 77 | foreach ($where as $condition => $values) { |
78 | 78 | |
79 | - if(!is_array($values)){ |
|
79 | + if (!is_array($values)) { |
|
80 | 80 | $w['AND'][] = $values; |
81 | 81 | continue; |
82 | 82 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | } |
89 | 89 | |
90 | - $this->where = array_merge($this->where,$w); |
|
90 | + $this->where = array_merge($this->where, $w); |
|
91 | 91 | |
92 | 92 | return $this; |
93 | 93 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $string = ''; |
148 | 148 | foreach ($this->data as $key => $value) { |
149 | 149 | |
150 | - if(gettype($value)==='object'){ |
|
150 | + if (gettype($value) === 'object') { |
|
151 | 151 | $value = $value->getData()[$this->primary]['value']; |
152 | 152 | } |
153 | 153 | |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | private function removeById(): bool |
160 | 160 | { |
161 | - $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
161 | + $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
162 | 162 | |
163 | 163 | $this->check_fail(); |
164 | 164 | |
@@ -167,12 +167,12 @@ discard block |
||
167 | 167 | |
168 | 168 | public function findById($id) |
169 | 169 | { |
170 | - return $this->where([$this->primary,'=',$id]); |
|
170 | + return $this->where([$this->primary, '=', $id]); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | public function execute() |
174 | 174 | { |
175 | - if(!is_null($this->clause) && $this->clause == 'remove'){ |
|
175 | + if (!is_null($this->clause) && $this->clause == 'remove') { |
|
176 | 176 | return $this->remove(true); |
177 | 177 | } |
178 | 178 | |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | |
181 | 181 | $this->mountSelect(); |
182 | 182 | |
183 | - $where = substr($this->mountWhereExec()['where'],0,-1); |
|
184 | - $where .= substr($this->mountBetweenExec()['where'],0,-1); |
|
183 | + $where = substr($this->mountWhereExec()['where'], 0, -1); |
|
184 | + $where .= substr($this->mountBetweenExec()['where'], 0, -1); |
|
185 | 185 | |
186 | 186 | $this->query .= " WHERE {$where} "; |
187 | 187 |
@@ -2,20 +2,20 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace HnrAzevedo\Datamanager; |
4 | 4 | |
5 | -trait MagicsTrait{ |
|
5 | +trait MagicsTrait { |
|
6 | 6 | |
7 | - public function __set(string $prop,$value) |
|
7 | + public function __set(string $prop, $value) |
|
8 | 8 | { |
9 | - if(is_array($value)){ |
|
9 | + if (is_array($value)) { |
|
10 | 10 | $attr = array_keys($value)[0]; |
11 | 11 | $this->data[$prop][$attr] = $value[$attr]; |
12 | 12 | return $this; |
13 | 13 | } |
14 | 14 | |
15 | - if($this->full){ |
|
16 | - switch($this->data[$prop]['type']){ |
|
15 | + if ($this->full) { |
|
16 | + switch ($this->data[$prop]['type']) { |
|
17 | 17 | case 'date': |
18 | - $value = (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value) , 'Y-m-d')); |
|
18 | + $value = (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value), 'Y-m-d')); |
|
19 | 19 | break; |
20 | 20 | } |
21 | 21 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | { |
33 | 33 | $this->isSettable($field); |
34 | 34 | |
35 | - if($this->full){ |
|
36 | - switch($this->data[$field]['type']){ |
|
37 | - case 'date': $this->data[$field]['value'] = (date_format( date_create_from_format('Y-m-d' , $this->data[$field]['value'] ) , DATAMANAGER_CONFIG['dateformat'])); |
|
35 | + if ($this->full) { |
|
36 | + switch ($this->data[$field]['type']) { |
|
37 | + case 'date': $this->data[$field]['value'] = (date_format(date_create_from_format('Y-m-d', $this->data[$field]['value']), DATAMANAGER_CONFIG['dateformat'])); |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 |
@@ -5,12 +5,12 @@ |
||
5 | 5 | use HnrAzevedo\Datamanager\Datamanager; |
6 | 6 | |
7 | 7 | /** |
8 | - * @property string $name |
|
9 | - * @property string $email |
|
10 | - * @property string $password |
|
11 | - * @property string birth |
|
12 | - * @property string register |
|
13 | - */ |
|
8 | + * @property string $name |
|
9 | + * @property string $email |
|
10 | + * @property string $password |
|
11 | + * @property string birth |
|
12 | + * @property string register |
|
13 | + */ |
|
14 | 14 | class User extends Datamanager{ |
15 | 15 | |
16 | 16 | public function __construct() |
@@ -11,11 +11,11 @@ |
||
11 | 11 | * @property string birth |
12 | 12 | * @property string register |
13 | 13 | */ |
14 | -class User extends Datamanager{ |
|
14 | +class User extends Datamanager { |
|
15 | 15 | |
16 | 16 | public function __construct() |
17 | 17 | { |
18 | - parent::create('user','id'); |
|
18 | + parent::create('user', 'id'); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | } |
22 | 22 | \ No newline at end of file |