@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | 6 | |
| 7 | -class DatamanagerException extends Exception{ |
|
| 7 | +class DatamanagerException extends Exception { |
|
| 8 | 8 | |
| 9 | 9 | public function __construct($message, $code = 0, Exception $previous = null) |
| 10 | 10 | { |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | public function __toString() |
| 15 | 15 | { |
| 16 | - return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; |
|
| 16 | + return __CLASS__.": [{$this->code}]: {$this->message}\n"; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | } |
| 20 | 20 | \ No newline at end of file |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $this->transaction('commit'); |
| 54 | 54 | |
| 55 | - }catch(DatamanagerException $er){ |
|
| 55 | + } catch(DatamanagerException $er){ |
|
| 56 | 56 | $this->transaction('rollback'); |
| 57 | 57 | throw $er; |
| 58 | 58 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $this->check_fail(); |
| 96 | 96 | |
| 97 | 97 | $this->transaction('commit'); |
| 98 | - }catch(DatamanagerException $er){ |
|
| 98 | + } catch(DatamanagerException $er){ |
|
| 99 | 99 | $this->transaction('rollback'); |
| 100 | 100 | throw $er; |
| 101 | 101 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use HnrAzevedo\Datamanager\DatamanagerException; |
| 6 | 6 | |
| 7 | -trait EntityTrait{ |
|
| 7 | +trait EntityTrait { |
|
| 8 | 8 | use CheckTrait; |
| 9 | 9 | |
| 10 | 10 | protected string $lastQuery = ''; |
@@ -12,13 +12,13 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | public function toEntity() |
| 14 | 14 | { |
| 15 | - if($this->getCount() === 0){ |
|
| 15 | + if ($this->getCount() === 0) { |
|
| 16 | 16 | return null; |
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | $entity = $this->setByDatabase($this->result[0]); |
| 20 | 20 | |
| 21 | - if(count($this->result) > 1){ |
|
| 21 | + if (count($this->result) > 1) { |
|
| 22 | 22 | $entity = []; |
| 23 | 23 | foreach ($this->result as $key => $value) { |
| 24 | 24 | $entity[] = $this->setByDatabase($value); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $data = []; |
| 36 | 36 | |
| 37 | 37 | foreach ($this->data as $key => $value) { |
| 38 | - if(strstr($this->data[$key]['extra'],'auto_increment')){ |
|
| 38 | + if (strstr($this->data[$key]['extra'], 'auto_increment')) { |
|
| 39 | 39 | continue; |
| 40 | 40 | } |
| 41 | 41 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $this->transaction('begin'); |
| 50 | - try{ |
|
| 50 | + try { |
|
| 51 | 51 | |
| 52 | 52 | $this->checkUniques($data); |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | $this->transaction('commit'); |
| 63 | 63 | |
| 64 | - }catch(DatamanagerException $er){ |
|
| 64 | + } catch (DatamanagerException $er) { |
|
| 65 | 65 | $this->transaction('rollback'); |
| 66 | 66 | throw $er; |
| 67 | 67 | } |
@@ -71,21 +71,21 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public function remove(bool $exec = false) |
| 73 | 73 | { |
| 74 | - if(!$exec){ |
|
| 74 | + if (!$exec) { |
|
| 75 | 75 | $this->clause = 'remove'; |
| 76 | 76 | return $this; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $this->clause = null; |
| 80 | 80 | |
| 81 | - if(count($this->where) == 1){ |
|
| 81 | + if (count($this->where) == 1) { |
|
| 82 | 82 | $this->removeById(); |
| 83 | 83 | return $this; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | $this->delete( |
| 87 | 87 | $this->mountRemove()['where'], |
| 88 | - substr( $this->mountRemove()['data'] ,0,-1) |
|
| 88 | + substr($this->mountRemove()['data'], 0, -1) |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | 91 | $this->check_fail(); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | { |
| 98 | 98 | $this->transaction('begin'); |
| 99 | 99 | |
| 100 | - try{ |
|
| 100 | + try { |
|
| 101 | 101 | $this->checkForChanges(); |
| 102 | 102 | |
| 103 | 103 | $this->update( |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | $this->check_fail(); |
| 110 | 110 | |
| 111 | 111 | $this->transaction('commit'); |
| 112 | - }catch(DatamanagerException $er){ |
|
| 112 | + } catch (DatamanagerException $er) { |
|
| 113 | 113 | $this->transaction('rollback'); |
| 114 | 114 | throw $er; |
| 115 | 115 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | use HnrAzevedo\Datamanager\DatamanagerException; |
| 10 | 10 | use Model\User; |
| 11 | 11 | |
| 12 | -try{ |
|
| 12 | +try { |
|
| 13 | 13 | $entity = new User(); |
| 14 | 14 | |
| 15 | 15 | $user = $entity->find()->execute()->first(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | /* NOTE: Must already have the Model returned from a query */ |
| 24 | 24 | $user->save(); |
| 25 | 25 | |
| 26 | -}catch(DatamanagerException $er){ |
|
| 26 | +} catch (DatamanagerException $er) { |
|
| 27 | 27 | |
| 28 | 28 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 29 | 29 | |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | /* NOTE: Must already have the Model returned from a query */ |
| 24 | 24 | $user->save(); |
| 25 | 25 | |
| 26 | -}catch(DatamanagerException $er){ |
|
| 26 | +} catch(DatamanagerException $er){ |
|
| 27 | 27 | |
| 28 | 28 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 29 | 29 | |
@@ -57,7 +57,7 @@ |
||
| 57 | 57 | /* Searches for all records and returns an array of Model\User objects */ |
| 58 | 58 | $results = $entity->find()->execute()->toEntity(); |
| 59 | 59 | |
| 60 | -}catch(DatamanagerException $er){ |
|
| 60 | +} catch(DatamanagerException $er){ |
|
| 61 | 61 | |
| 62 | 62 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 63 | 63 | |
@@ -9,21 +9,21 @@ discard block |
||
| 9 | 9 | use HnrAzevedo\Datamanager\DatamanagerException; |
| 10 | 10 | use Model\User; |
| 11 | 11 | |
| 12 | -try{ |
|
| 12 | +try { |
|
| 13 | 13 | $entity = new User(); |
| 14 | 14 | |
| 15 | 15 | /* Find by primary key */ |
| 16 | 16 | $user = $entity->find(1)->execute()->first()->toEntity(); |
| 17 | 17 | |
| 18 | 18 | /* Search only for columns defined in advance */ |
| 19 | - $user = $entity->find(1)->only(['name','email'])->execute()->first(); |
|
| 19 | + $user = $entity->find(1)->only(['name', 'email'])->execute()->first(); |
|
| 20 | 20 | $name = $user->name; |
| 21 | 21 | $email = $user->email; |
| 22 | 22 | /* OR */ |
| 23 | 23 | $name = $entity->find()->only('name')->execute()->first()->name; |
| 24 | 24 | |
| 25 | 25 | /* Search except for columns defined in advance */ |
| 26 | - $user = $entity->find()->except(['name','email'])->execute()->first(); |
|
| 26 | + $user = $entity->find()->except(['name', 'email'])->execute()->first(); |
|
| 27 | 27 | /* OR */ |
| 28 | 28 | $user = $entity->find()->except('name')->execute()->first(); |
| 29 | 29 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | /* OrdeBy example */ |
| 36 | 36 | $users = $entity->find()->orderBy('birth ASC')->execute()->result(); |
| 37 | 37 | /* OR */ |
| 38 | - $users = $entity->find()->orderBy('birth','ASC')->execute()->result(); |
|
| 38 | + $users = $entity->find()->orderBy('birth', 'ASC')->execute()->result(); |
|
| 39 | 39 | |
| 40 | 40 | |
| 41 | 41 | /* Between example */ |
@@ -65,9 +65,9 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | /* Where example */ |
| 67 | 67 | $user->find()->where([ |
| 68 | - ['name','=','Henri Azevedo'], |
|
| 68 | + ['name', '=', 'Henri Azevedo'], |
|
| 69 | 69 | 'OR' => [ |
| 70 | - 'email','LIKE','[email protected]' |
|
| 70 | + 'email', 'LIKE', '[email protected]' |
|
| 71 | 71 | ] |
| 72 | 72 | ])->execute(); |
| 73 | 73 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | /* Searches for all records and returns an array of Model\User objects */ |
| 78 | 78 | $results = $entity->find()->execute()->toEntity(); |
| 79 | 79 | |
| 80 | -}catch(DatamanagerException $er){ |
|
| 80 | +} catch (DatamanagerException $er) { |
|
| 81 | 81 | |
| 82 | 82 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 83 | 83 | |
@@ -9,13 +9,13 @@ discard block |
||
| 9 | 9 | use HnrAzevedo\Datamanager\DatamanagerException; |
| 10 | 10 | use Model\User; |
| 11 | 11 | |
| 12 | -try{ |
|
| 12 | +try { |
|
| 13 | 13 | $entity = new User(); |
| 14 | 14 | |
| 15 | 15 | /* Remove by cause *Where* */ |
| 16 | 16 | $entity->remove()->where([ |
| 17 | - ['name','=','Other Name'], |
|
| 18 | - 'OR' => ['email','LIKE','[email protected]'] |
|
| 17 | + ['name', '=', 'Other Name'], |
|
| 18 | + 'OR' => ['email', 'LIKE', '[email protected]'] |
|
| 19 | 19 | ])->execute(); |
| 20 | 20 | |
| 21 | 21 | /* Remove by primary key */ |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | /* OR */ |
| 25 | 25 | $entity->remove(true); |
| 26 | 26 | |
| 27 | -}catch(DatamanagerException $er){ |
|
| 27 | +} catch (DatamanagerException $er) { |
|
| 28 | 28 | |
| 29 | 29 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 30 | 30 | |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | /* OR */ |
| 25 | 25 | $entity->remove(true); |
| 26 | 26 | |
| 27 | -}catch(DatamanagerException $er){ |
|
| 27 | +} catch(DatamanagerException $er){ |
|
| 28 | 28 | |
| 29 | 29 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 30 | 30 | |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | /* Insert entity in database */ |
| 25 | 25 | $entity->persist(); |
| 26 | 26 | |
| 27 | -}catch(DatamanagerException $er){ |
|
| 27 | +} catch(DatamanagerException $er){ |
|
| 28 | 28 | |
| 29 | 29 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 30 | 30 | |
@@ -11,20 +11,20 @@ |
||
| 11 | 11 | use HnrAzevedo\Datamanager\DatamanagerException; |
| 12 | 12 | use Model\User; |
| 13 | 13 | |
| 14 | -try{ |
|
| 14 | +try { |
|
| 15 | 15 | $entity = new User(); |
| 16 | 16 | |
| 17 | 17 | /* Set new info for insert in database */ |
| 18 | 18 | $entity->name = 'Henri Azevedo'; |
| 19 | 19 | $entity->email = '[email protected]'; |
| 20 | - $entity->password = password_hash('123456' ,PASSWORD_DEFAULT); |
|
| 20 | + $entity->password = password_hash('123456', PASSWORD_DEFAULT); |
|
| 21 | 21 | $entity->birth = '28/09/1996'; |
| 22 | 22 | $entity->register = date('Y-m-d H:i:s'); |
| 23 | 23 | |
| 24 | 24 | /* Insert entity in database */ |
| 25 | 25 | $entity->persist(); |
| 26 | 26 | |
| 27 | -}catch(DatamanagerException $er){ |
|
| 27 | +} catch (DatamanagerException $er) { |
|
| 28 | 28 | |
| 29 | 29 | die("Code Error: {$er->getCode()}, Line: {$er->getLine()}, File: {$er->getFile()}, Message: {$er->getMessage()}."); |
| 30 | 30 | |
@@ -15,24 +15,24 @@ |
||
| 15 | 15 | if (empty(self::$instance)) { |
| 16 | 16 | try { |
| 17 | 17 | |
| 18 | - if(!defined('DATAMANAGER_CONFIG')){ |
|
| 18 | + if (!defined('DATAMANAGER_CONFIG')) { |
|
| 19 | 19 | throw new DatamanagerException("Information for connection to the database not defined."); |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | self::$instance = new PDO( |
| 23 | - DATAMANAGER_CONFIG['driver'] . ':host='.DATAMANAGER_CONFIG['host'] . ';port='.DATAMANAGER_CONFIG['port'] . ';dbname='.DATAMANAGER_CONFIG['database'] . ';charset='.DATAMANAGER_CONFIG['charset'], |
|
| 23 | + DATAMANAGER_CONFIG['driver'].':host='.DATAMANAGER_CONFIG['host'].';port='.DATAMANAGER_CONFIG['port'].';dbname='.DATAMANAGER_CONFIG['database'].';charset='.DATAMANAGER_CONFIG['charset'], |
|
| 24 | 24 | DATAMANAGER_CONFIG['username'], |
| 25 | 25 | DATAMANAGER_CONFIG['password'], |
| 26 | 26 | DATAMANAGER_CONFIG['options'] |
| 27 | 27 | ); |
| 28 | 28 | } catch (Exception $exception) { |
| 29 | - throw new DatamanagerException(str_replace(['SQLSTATE[HY000]',"[{$exception->getCode()}]"], '', $exception->getMessage()), $exception->getCode(), $exception); |
|
| 29 | + throw new DatamanagerException(str_replace(['SQLSTATE[HY000]', "[{$exception->getCode()}]"], '', $exception->getMessage()), $exception->getCode(), $exception); |
|
| 30 | 30 | } |
| 31 | 31 | } |
| 32 | 32 | return self::$instance; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public static function destroy(){ |
|
| 35 | + public static function destroy() { |
|
| 36 | 36 | self::$instance = null; |
| 37 | 37 | } |
| 38 | 38 | |
@@ -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; |
@@ -25,15 +25,15 @@ discard block |
||
| 25 | 25 | { |
| 26 | 26 | $return = ['data' => '', 'where' => '']; |
| 27 | 27 | $c = -1; |
| 28 | - foreach($this->where as $clause => $condition){ |
|
| 28 | + foreach ($this->where as $clause => $condition) { |
|
| 29 | 29 | $c++; |
| 30 | - if(strlen($clause) === 0){ |
|
| 30 | + if (strlen($clause) === 0) { |
|
| 31 | 31 | $return['where'] .= " {$clause} {$condition[0]} {$condition[1]} :q_{$condition[0]}{$c} "; |
| 32 | 32 | $return['data'] .= "q_{$condition[0]}={$condition[2]}{$c}&"; |
| 33 | 33 | continue; |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | - foreach($condition as $value){ |
|
| 36 | + foreach ($condition as $value) { |
|
| 37 | 37 | $return['where'] .= " {$clause} {$value[0]} {$value[1]} :q_{$value[0]}{$c} "; |
| 38 | 38 | $return['data'] .= "q_{$value[0]}={$value[2]}{$c}&"; |
| 39 | 39 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | $return = ['data' => []]; |
| 47 | 47 | |
| 48 | 48 | foreach ($this->data as $key => $value) { |
| 49 | - if($this->upgradeable($key) && !$this->isIncremented($key)){ |
|
| 49 | + if ($this->upgradeable($key) && !$this->isIncremented($key)) { |
|
| 50 | 50 | $return['data'][$key] = $this->data[$key]['value']; |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -57,9 +57,9 @@ discard block |
||
| 57 | 57 | private function mountWheres(array $value, string $key, int $c): array |
| 58 | 58 | { |
| 59 | 59 | $return = ['where' => '', 'data' => []]; |
| 60 | - for($i = 0; $i < count($value); $i++){ |
|
| 60 | + for ($i = 0; $i < count($value); $i++) { |
|
| 61 | 61 | |
| 62 | - if(!is_array($value[$i][2])){ |
|
| 62 | + if (!is_array($value[$i][2])) { |
|
| 63 | 63 | $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} :q_{$value[$i][0]}{$c}{$i} "; |
| 64 | 64 | $return['data']["q_{$value[$i][0]}{$c}{$i}"] = $value[$i][2]; |
| 65 | 65 | continue; |
@@ -67,12 +67,12 @@ discard block |
||
| 67 | 67 | |
| 68 | 68 | $return['where'] .= " {$key} {$value[$i][0]} {$value[$i][1]} ("; |
| 69 | 69 | |
| 70 | - foreach($value[$i][2] as $v => $valu){ |
|
| 70 | + foreach ($value[$i][2] as $v => $valu) { |
|
| 71 | 71 | $return['where'] .= " :q_{$value[$i][0]}{$c}{$i}_{$v},"; |
| 72 | 72 | $return['data']["q_{$value[$i][0]}{$c}{$i}_{$v}"] = $valu; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $return['where'] = substr($return['where'],0,-1) .') '; |
|
| 75 | + $return['where'] = substr($return['where'], 0, -1).') '; |
|
| 76 | 76 | } |
| 77 | 77 | return $return; |
| 78 | 78 | } |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | $c++; |
| 86 | 86 | $key = (!$key) ? '' : " {$key} "; |
| 87 | 87 | |
| 88 | - if(!is_array($value[0])){ |
|
| 88 | + if (!is_array($value[0])) { |
|
| 89 | 89 | $return['where'] .= " {$key} {$value[0]} {$value[1]} :q_{$value[0]}{$c} "; |
| 90 | 90 | $return['data']["q_{$value[0]}{$c}"] = $value[2]; |
| 91 | 91 | continue; |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | $altReturn = $this->mountWheres($value, $key, $c); |
| 95 | 95 | $return['where'] .= $altReturn['where']; |
| 96 | - $return['data'] = array_merge($return['data'],$altReturn['data']); |
|
| 96 | + $return['data'] = array_merge($return['data'], $altReturn['data']); |
|
| 97 | 97 | |
| 98 | 98 | } |
| 99 | 99 | return $return; |
@@ -104,14 +104,14 @@ discard block |
||
| 104 | 104 | $return = ['where' => '', 'data' => []]; |
| 105 | 105 | |
| 106 | 106 | $c = -1; |
| 107 | - foreach($this->between as $field => $value){ |
|
| 107 | + foreach ($this->between as $field => $value) { |
|
| 108 | 108 | $c++; |
| 109 | - $condition = (count(explode(' ',$field)) > 2) ? ' '.explode(' ',$field)[0].' ' : ' AND '; |
|
| 110 | - $field = str_replace(['AND','OR',' '],'',$field); |
|
| 109 | + $condition = (count(explode(' ', $field)) > 2) ? ' '.explode(' ', $field)[0].' ' : ' AND '; |
|
| 110 | + $field = str_replace(['AND', 'OR', ' '], '', $field); |
|
| 111 | 111 | $return['where'] .= " {$condition} {$field} BETWEEN :q_1{$field}{$c} AND :q_2{$field}{$c} "; |
| 112 | 112 | $return['data'] = [ |
| 113 | - "q_1{$field}{$c}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[0]) , 'Y-m-d')), |
|
| 114 | - "q_2{$field}{$c}" => (date_format( date_create_from_format(DATAMANAGER_CONFIG['dateformat'],$value[1]) , 'Y-m-d')) |
|
| 113 | + "q_1{$field}{$c}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[0]), 'Y-m-d')), |
|
| 114 | + "q_2{$field}{$c}" => (date_format(date_create_from_format(DATAMANAGER_CONFIG['dateformat'], $value[1]), 'Y-m-d')) |
|
| 115 | 115 | ]; |
| 116 | 116 | } |
| 117 | 117 | return $return; |
@@ -119,21 +119,21 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | protected function mountSelect() |
| 121 | 121 | { |
| 122 | - $select = implode(',',array_keys($this->select)); |
|
| 122 | + $select = implode(',', array_keys($this->select)); |
|
| 123 | 123 | |
| 124 | - $this->query = str_replace('*', $select,$this->query); |
|
| 124 | + $this->query = str_replace('*', $select, $this->query); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | protected function mountLimit() |
| 128 | 128 | { |
| 129 | - if(!is_null($this->limit)){ |
|
| 129 | + if (!is_null($this->limit)) { |
|
| 130 | 130 | $this->query .= " LIMIT {$this->limit}"; |
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | protected function mountOffset() |
| 135 | 135 | { |
| 136 | - if(!is_null($this->offset)){ |
|
| 136 | + if (!is_null($this->offset)) { |
|
| 137 | 137 | $this->query .= " OFFSET {$this->offset}"; |
| 138 | 138 | } |
| 139 | 139 | } |
@@ -4,36 +4,36 @@ discard block |
||
| 4 | 4 | |
| 5 | 5 | use HnrAzevedo\Datamanager\DatamanagerException; |
| 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 DatamanagerException("Condition where set incorrectly: ".implode(' ',$where)); |
|
| 11 | + if (count($where) != 3) { |
|
| 12 | + throw new DatamanagerException("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 DatamanagerException("{$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 DatamanagerException("{$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 DatamanagerException("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 DatamanagerException("The information provided for column {$field} of table {$this->table} exceeded that allowed."); |
| 38 | 38 | } |
| 39 | 39 | } |
@@ -45,18 +45,18 @@ 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 | |
| 51 | 51 | protected function checkForChanges(): bool |
| 52 | 52 | { |
| 53 | 53 | $hasChanges = false; |
| 54 | - foreach($this->data as $data){ |
|
| 55 | - if($data['changed']){ |
|
| 54 | + foreach ($this->data as $data) { |
|
| 55 | + if ($data['changed']) { |
|
| 56 | 56 | $hasChanges = true; |
| 57 | 57 | } |
| 58 | 58 | } |
| 59 | - if(!$hasChanges){ |
|
| 59 | + if (!$hasChanges) { |
|
| 60 | 60 | throw new DatamanagerException('There were no changes to be saved in the database.'); |
| 61 | 61 | } |
| 62 | 62 | return true; |
@@ -64,10 +64,10 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | protected function checkUniques($data) |
| 66 | 66 | { |
| 67 | - foreach($this->data as $d => $dd){ |
|
| 68 | - if($dd['key'] === 'UNI'){ |
|
| 69 | - $exist = $this->find()->where([$d,'=',$data[$d]])->only('id')->execute()->getCount(); |
|
| 70 | - if($exist > 0){ |
|
| 67 | + foreach ($this->data as $d => $dd) { |
|
| 68 | + if ($dd['key'] === 'UNI') { |
|
| 69 | + $exist = $this->find()->where([$d, '=', $data[$d]])->only('id')->execute()->getCount(); |
|
| 70 | + if ($exist > 0) { |
|
| 71 | 71 | throw new DatamanagerException("A record with the same {$this->getField($d)} already exists."); |
| 72 | 72 | } |
| 73 | 73 | } |