Passed
Branch master (4271e9)
by Henri
01:50 queued 30s
created
src/EntityTrait.php 1 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.
src/CheckTrait.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -4,36 +4,36 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             }
Please login to merge, or discard this patch.