Passed
Branch master (0f077f)
by Henri
01:20
created
src/CrudTrait.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -6,24 +6,24 @@  discard block
 block discarded – undo
6 6
 use Exception;
7 7
 use PDO;
8 8
 
9
-trait CrudTrait{
9
+trait CrudTrait {
10 10
 
11 11
     protected ?DatamanagerException $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 DatamanagerException("{$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
 block discarded – undo
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 = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
45 45
         }
46 46
         return [];
@@ -48,11 +48,11 @@  discard block
 block discarded – undo
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 = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
57 57
             return [];
58 58
         }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
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
 
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         try {
104 104
             $stmt = Connect::getInstance()->prepare("DELETE FROM {$this->table} WHERE {$terms}");
105 105
 
106
-            if($params){
106
+            if ($params) {
107 107
                 parse_str($params, $arr);
108 108
                 $stmt->execute($arr);
109 109
                 return true;
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
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 = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
45 45
         }
46 46
         return [];
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
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 = new DatamanagerException($exception->getMessage(), $exception->getCode(), $exception);
57 57
             return [];
58 58
         }
Please login to merge, or discard this patch.
src/DatamanagerException.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
Please login to merge, or discard this patch.
src/EntityTrait.php 2 patches
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,18 +4,18 @@  discard block
 block discarded – undo
4 4
 
5 5
 use HnrAzevedo\Datamanager\DatamanagerException;
6 6
 
7
-trait EntityTrait{
7
+trait EntityTrait {
8 8
     use CheckTrait;
9 9
     
10 10
     public function toEntity()
11 11
     {
12
-        if($this->getCount() === 0){
12
+        if ($this->getCount() === 0) {
13 13
             return null;
14 14
         }
15 15
 
16 16
         $entity = $this->setByDatabase($this->result[0]);
17 17
 
18
-        if(count($this->result) > 1){
18
+        if (count($this->result) > 1) {
19 19
             $entity = [];
20 20
             foreach ($this->result as $key => $value) {
21 21
                 $entity[] = $this->setByDatabase($value);
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
         $data = [];
33 33
 
34 34
         foreach ($this->data as $key => $value) {
35
-            if(strstr($this->data[$key]['extra'],'auto_increment')){
35
+            if (strstr($this->data[$key]['extra'], 'auto_increment')) {
36 36
                 continue;
37 37
             }
38 38
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
         }
45 45
 
46 46
         $this->transaction('begin');
47
-        try{
47
+        try {
48 48
 
49 49
             $this->checkUniques($data);
50 50
            
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
             
59 59
             $this->transaction('commit');
60 60
 
61
-        }catch(DatamanagerException $er){
61
+        } catch (DatamanagerException $er) {
62 62
             $this->transaction('rollback');
63 63
             throw $er;
64 64
         }
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
 
69 69
     public function remove(bool $exec = false)
70 70
     {
71
-        if(!$exec){
71
+        if (!$exec) {
72 72
             $this->clause = 'remove';    
73 73
             return $this;
74 74
         }
75 75
 
76 76
         $this->clause = null;
77 77
 
78
-        if(count($this->where) == 1){
78
+        if (count($this->where) == 1) {
79 79
             $this->removeById();
80 80
             return $this;
81 81
         }
82 82
 
83
-        $this->delete($this->mountRemove()['where'], substr( $this->mountRemove()['data'] ,0,-1) );
83
+        $this->delete($this->mountRemove()['where'], substr($this->mountRemove()['data'], 0, -1));
84 84
 
85 85
         $this->check_fail();
86 86
             
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
     {
92 92
         $this->transaction('begin');
93 93
 
94
-        try{
94
+        try {
95 95
             $this->checkForChanges();
96 96
             
97 97
             $this->update(
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
             $this->check_fail();
104 104
 
105 105
             $this->transaction('commit');
106
-        }catch(DatamanagerException $er){
106
+        } catch (DatamanagerException $er) {
107 107
             $this->transaction('rollback');
108 108
             throw $er;
109 109
         }
Please login to merge, or discard this patch.
examples/Upload.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
examples/Select.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -9,21 +9,21 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
examples/Remove.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -9,13 +9,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
examples/Insert.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -11,20 +11,20 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/SynchronizeTrait.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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','bigtint','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', 'bigtint', '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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Connect.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,24 +15,24 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.