@@ -5,12 +5,12 @@ |
||
5 | 5 | use HnrAzevedo\Datamanager\Model as Entity; |
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 Entity{ |
15 | 15 | |
16 | 16 | public function __construct() |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @property string birth |
12 | 12 | * @property string register |
13 | 13 | */ |
14 | -class User extends Entity{ |
|
14 | +class User extends Entity { |
|
15 | 15 | |
16 | 16 | public function __construct() |
17 | 17 | { |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * @param string Table name |
24 | 24 | * @param string Primary key column |
25 | 25 | */ |
26 | - parent::create('user','id'); |
|
26 | + parent::create('user', 'id'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | } |
30 | 30 | \ No newline at end of file |
@@ -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 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | public function getVars(): array |
32 | 32 | { |
33 | 33 | $vars = []; |
34 | - foreach($this->data as $var => $value){ |
|
34 | + foreach ($this->data as $var => $value) { |
|
35 | 35 | $vars[$var] = null; |
36 | 36 | } |
37 | 37 | return $vars; |
@@ -41,13 +41,13 @@ discard block |
||
41 | 41 | { |
42 | 42 | $this->isSettable($field); |
43 | 43 | |
44 | - if($this->full){ |
|
45 | - switch($this->data[$field]['type']){ |
|
44 | + if ($this->full) { |
|
45 | + switch ($this->data[$field]['type']) { |
|
46 | 46 | case 'date': |
47 | - return (!empty($this->data[$field]['value'])) ? (@date_format( @date_create_from_format('Y-m-d' , $this->data[$field]['value'] ) , DATAMANAGER_CONFIG['dateformat'])) : null ; |
|
47 | + return (!empty($this->data[$field]['value'])) ? (@date_format(@date_create_from_format('Y-m-d', $this->data[$field]['value']), DATAMANAGER_CONFIG['dateformat'])) : null; |
|
48 | 48 | break; |
49 | 49 | case 'datetime': |
50 | - return (!empty($this->data[$field]['value'])) ? (@date_format( @date_create_from_format('Y-m-d H:i:s' , $this->data[$field]['value'] ) , DATAMANAGER_CONFIG['datetimeformat'])) : null ; |
|
50 | + return (!empty($this->data[$field]['value'])) ? (@date_format(@date_create_from_format('Y-m-d H:i:s', $this->data[$field]['value']), DATAMANAGER_CONFIG['datetimeformat'])) : null; |
|
51 | 51 | break; |
52 | 52 | } |
53 | 53 | } |
@@ -2,13 +2,13 @@ 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; |
9 | 9 | protected ?string $primary = null; |
10 | 10 | protected bool $full = false; |
11 | - protected static ?array $describe = null; |
|
11 | + protected static ? array $describe = null; |
|
12 | 12 | |
13 | 13 | protected function synchronize(string $table, ?string $primary = null) |
14 | 14 | { |
@@ -43,10 +43,10 @@ discard block |
||
43 | 43 | { |
44 | 44 | $type = $value; |
45 | 45 | |
46 | - if(strpos($value,'(')){ |
|
47 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['varchar','char','text'])) ? 'string' : $type; |
|
48 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['tinyint','mediumint','smallint','bigint','int'])) ? 'int' : $type; |
|
49 | - $type = (in_array( substr($value, 0, strpos($value,'(')) , ['decimal','float','double','real'])) ? 'float' : $type; |
|
46 | + if (strpos($value, '(')) { |
|
47 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['varchar', 'char', 'text'])) ? 'string' : $type; |
|
48 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['tinyint', 'mediumint', 'smallint', 'bigint', 'int'])) ? 'int' : $type; |
|
49 | + $type = (in_array(substr($value, 0, strpos($value, '(')), ['decimal', 'float', 'double', 'real'])) ? 'float' : $type; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | $this->mountTable_Maxlength($field, $type, $value); |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | |
56 | 56 | protected function mountTable_Maxlength(string $field, string $type, $default = null) |
57 | 57 | { |
58 | - $maxlength = (in_array( $type , ['string','float','int'])) ? substr($default,(strpos($default,'(')+1),-1) : 0; |
|
59 | - $maxlength = (in_array( $type , ['date'])) ? 10 : $maxlength; |
|
60 | - $maxlength = (in_array( $type , ['datetime'])) ? 19 : $maxlength; |
|
61 | - $maxlength = (in_array( $type , ['boolean'])) ? 1 : $maxlength; |
|
58 | + $maxlength = (in_array($type, ['string', 'float', 'int'])) ? substr($default, (strpos($default, '(') + 1), -1) : 0; |
|
59 | + $maxlength = (in_array($type, ['date'])) ? 10 : $maxlength; |
|
60 | + $maxlength = (in_array($type, ['datetime'])) ? 19 : $maxlength; |
|
61 | + $maxlength = (in_array($type, ['boolean'])) ? 1 : $maxlength; |
|
62 | 62 | $this->$field = ['maxlength' => $maxlength]; |
63 | 63 | } |
64 | 64 |
@@ -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'): Datamanager |
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; |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | $this->select[$field] = true; |
67 | 67 | } |
68 | 68 | |
69 | - if(!is_null($this->primary)){ |
|
69 | + if (!is_null($this->primary)) { |
|
70 | 70 | $this->select[$this->primary] = true; |
71 | 71 | } |
72 | 72 | return $this; |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | |
75 | 75 | public function where(array $where): Datamanager |
76 | 76 | { |
77 | - $this->where['AND'] = (array_key_exists('AND',$this->where)) ?? ''; |
|
77 | + $this->where['AND'] = (array_key_exists('AND', $this->where)) ?? ''; |
|
78 | 78 | $w = []; |
79 | 79 | foreach ($where as $condition => $values) { |
80 | 80 | |
81 | - if(!is_array($values)){ |
|
81 | + if (!is_array($values)) { |
|
82 | 82 | $w['AND'][] = $values; |
83 | 83 | continue; |
84 | 84 | } |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | |
90 | 90 | } |
91 | 91 | |
92 | - $this->where = array_merge($this->where,$w); |
|
92 | + $this->where = array_merge($this->where, $w); |
|
93 | 93 | |
94 | 94 | return $this; |
95 | 95 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | $string = ''; |
150 | 150 | foreach ($this->data as $key => $value) { |
151 | 151 | |
152 | - if(gettype($value)==='object'){ |
|
152 | + if (gettype($value) === 'object') { |
|
153 | 153 | $value = $value->getData()[$this->primary]['value']; |
154 | 154 | } |
155 | 155 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | |
161 | 161 | private function removeById(): bool |
162 | 162 | { |
163 | - $delete = $this->delete("{$this->primary}=:{$this->primary}","{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
163 | + $delete = $this->delete("{$this->primary}=:{$this->primary}", "{$this->primary}={$this->getData()[$this->primary]['value']}"); |
|
164 | 164 | |
165 | 165 | $this->check_fail(); |
166 | 166 | |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | |
170 | 170 | public function findById($id): Datamanager |
171 | 171 | { |
172 | - return $this->where([$this->primary,'=',$id]); |
|
172 | + return $this->where([$this->primary, '=', $id]); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | public function execute(): Datamanager |
176 | 176 | { |
177 | - if(!is_null($this->clause) && $this->clause == 'remove'){ |
|
177 | + if (!is_null($this->clause) && $this->clause == 'remove') { |
|
178 | 178 | return $this->remove(true); |
179 | 179 | } |
180 | 180 | |
@@ -182,8 +182,8 @@ discard block |
||
182 | 182 | |
183 | 183 | $this->mountSelect(); |
184 | 184 | |
185 | - $where = substr($this->mountWhereExec()['where'],0,-1); |
|
186 | - $where .= substr($this->mountBetweenExec()['where'],0,-1); |
|
185 | + $where = substr($this->mountWhereExec()['where'], 0, -1); |
|
186 | + $where .= substr($this->mountBetweenExec()['where'], 0, -1); |
|
187 | 187 | |
188 | 188 | $this->query .= " WHERE {$where} "; |
189 | 189 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | $this->count = count($this->result); |
206 | 206 | $this->query = null; |
207 | - $this->where = [''=> ["1",'=',"1"] ]; |
|
207 | + $this->where = [''=> ["1", '=', "1"]]; |
|
208 | 208 | |
209 | 209 | return $this; |
210 | 210 | } |
@@ -9,14 +9,14 @@ |
||
9 | 9 | |
10 | 10 | public function debug(bool $array = false) |
11 | 11 | { |
12 | - if($array){ |
|
12 | + if ($array) { |
|
13 | 13 | return ['query' => $this->lastQuery, 'data' => $this->lastData]; |
14 | 14 | } |
15 | 15 | |
16 | 16 | $query = $this->lastQuery; |
17 | 17 | |
18 | - foreach($this->lastData as $name => $value){ |
|
19 | - $query = str_replace(":{$name}","'{$value}'",$query); |
|
18 | + foreach ($this->lastData as $name => $value) { |
|
19 | + $query = str_replace(":{$name}", "'{$value}'", $query); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | return $query; |