Passed
Push — master ( d07642...e03816 )
by Fran
02:05
created
src/NOSQL/Dto/Model/NOSQLModelDto.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     public function setPk(string $id)
53 53
     {
54
-        if(!empty($this->_id)) {
54
+        if (!empty($this->_id)) {
55 55
             throw new NOSQLValidationException(t('Primary key already defined'), NOSQLValidationException::NOSQL_VALIDATION_ID_ALREADY_DEFINED);
56 56
         }
57 57
         $this->_id = $id;
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     public function getLastUpdate($format = null)
65 65
     {
66 66
         $value = $this->_last_update;
67
-        if(null !== $format) {
67
+        if (null !== $format) {
68 68
 
69 69
         }
70 70
         return $value;
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
     public function validate($throwException = false) {
105 105
         $errors = [];
106 106
         $reflection = new \ReflectionClass(get_called_class());
107
-        foreach($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
107
+        foreach ($reflection->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
108 108
             $required = InjectorHelper::checkIsRequired($property->getDocComment());
109 109
             $value = $property->getValue($this);
110
-            if($required && empty($value)) {
111
-                if($throwException) {
110
+            if ($required && empty($value)) {
111
+                if ($throwException) {
112 112
                     throw new NOSQLValidationException(t('Empty value for property ') . $property->getName(), NOSQLValidationException::NOSQL_VALIDATION_REQUIRED);
113 113
                 } else {
114 114
                     $errors[] = $property->getName();
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
     public function toArray()
124 124
     {
125 125
         $array = parent::toArray();
126
-        if(null !== $this->getPk()) {
126
+        if (null !== $this->getPk()) {
127 127
             $array['_id'] = $this->getPk();
128 128
         }
129
-        if(null !== $this->getName()) {
129
+        if (null !== $this->getName()) {
130 130
             $array[Api::API_LIST_NAME_FIELD] = $this->getName();
131 131
         }
132 132
         $array['_last_update'] = $this->getLastUpdate(\DateTime::ATOM);
@@ -150,10 +150,10 @@  discard block
 block discarded – undo
150 150
                 if (!is_numeric($value)) {
151 151
                     $errors[] = $property->getName();
152 152
                 } else {
153
-                    if(NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) {
154
-                        $property->setValue($this, (integer)$value);
153
+                    if (NOSQLBase::NOSQL_TYPE_INTEGER === strtolower($type)) {
154
+                        $property->setValue($this, (integer) $value);
155 155
                     } else {
156
-                        $property->setValue($this, (float)$value);
156
+                        $property->setValue($this, (float) $value);
157 157
                     }
158 158
                 }
159 159
                 break;
@@ -175,16 +175,16 @@  discard block
 block discarded – undo
175 175
                 if (!in_array($value, [true, false, 0, 1])) {
176 176
                     $errors[] = $property->getName();
177 177
                 }
178
-                $property->setValue($this, (bool)$value);
178
+                $property->setValue($this, (bool) $value);
179 179
                 break;
180 180
             case NOSQLBase::NOSQL_TYPE_DATE:
181 181
             case NOSQLBase::NOSQL_TYPE_TIMESTAMP:
182 182
                 $dateTime = new \DateTime($value, new \DateTimeZone('UTC'));
183
-                if(!$dateTime) {
183
+                if (!$dateTime) {
184 184
                     $errors[] = $property->getName();
185 185
                 } else {
186 186
                     $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));
187
-                    $property->setValue($this, new UTCDateTime($dateTime->getTimestamp()*1000));
187
+                    $property->setValue($this, new UTCDateTime($dateTime->getTimestamp() * 1000));
188 188
                 }
189 189
                 break;
190 190
         }
Please login to merge, or discard this patch.
src/NOSQL/Models/NOSQLActiveRecord.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function getDtoCopy($cleanPk = false) {
45 45
         $copy = clone $this->dto;
46
-        if($cleanPk) {
46
+        if ($cleanPk) {
47 47
             $this->dto->resetPk();
48 48
         }
49 49
         return $copy;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      */
60 60
     public function save(Database $con = null) {
61 61
         $saved = false;
62
-        if(null === $con) {
62
+        if (null === $con) {
63 63
             $con = ParserService::getInstance()->createConnection($this->getDomain());
64 64
         }
65 65
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             $isInsert = $isUpdate = false;
68 68
             $this->prepareData();
69 69
             $this->dto->setLastUpdate();
70
-            if($this->isNew()) {
70
+            if ($this->isNew()) {
71 71
                 $this->preInsert($con);
72 72
                 $isInsert = true;
73 73
             } elseif ($this->isModified()) {
@@ -75,19 +75,19 @@  discard block
 block discarded – undo
75 75
                 $isUpdate = true;
76 76
             }
77 77
             $result = $collection->insertOne($this->toArray());
78
-            if($result->getInsertedCount() > 0) {
78
+            if ($result->getInsertedCount() > 0) {
79 79
                 $id = $result->getInsertedId();
80 80
                 $this->dto->setPk($id->jsonSerialize()['$oid']);
81
-                if($isInsert) {
81
+                if ($isInsert) {
82 82
                     $this->postInsert($con);
83
-                } elseif($isUpdate) {
83
+                } elseif ($isUpdate) {
84 84
                     $this->postUpdate($con);
85 85
                 }
86 86
                 $saved = true;
87 87
                 $this->countAction();
88 88
             }
89
-        } catch(\Exception $exception) {
90
-            if($exception instanceof NOSQLValidationException) {
89
+        } catch (\Exception $exception) {
90
+            if ($exception instanceof NOSQLValidationException) {
91 91
                 throw $exception;
92 92
             } else {
93 93
                 Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     public function update(Database $con = null) {
104 104
         $updated = false;
105
-        if(null === $con) {
105
+        if (null === $con) {
106 106
             $con = ParserService::getInstance()->createConnection($this->getDomain());
107 107
         }
108 108
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
             $this->postUpdate($con);
117 117
             $updated = true;
118 118
             $this->countAction();
119
-        } catch(\Exception $exception) {
120
-            if($exception instanceof NOSQLValidationException) {
119
+        } catch (\Exception $exception) {
120
+            if ($exception instanceof NOSQLValidationException) {
121 121
                 throw $exception;
122 122
             } else {
123 123
                 Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      */
134 134
     public function bulkInsert(array $data, Database $con = null) {
135 135
         $inserts = 0;
136
-        if(null === $con) {
136
+        if (null === $con) {
137 137
             $con = ParserService::getInstance()->createConnection($this->getDomain());
138 138
         }
139 139
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             $ids = $result->getInsertedIds();
144 144
             $inserts = $this->parseInsertedDtos($con, $ids, $dtos);
145 145
             $this->setActionCount($inserts);
146
-        } catch(\Exception $exception) {
146
+        } catch (\Exception $exception) {
147 147
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
148 148
         }
149 149
         return $inserts;
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function delete(Database $con = null) {
157 157
         $deleted = false;
158
-        if(null === $con) {
158
+        if (null === $con) {
159 159
             $con = ParserService::getInstance()->createConnection($this->getDomain());
160 160
         }
161 161
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
             $deleted = true;
167 167
             $this->dto = null;
168 168
             $this->countAction();
169
-        } catch(\Exception $exception) {
169
+        } catch (\Exception $exception) {
170 170
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
171 171
         }
172 172
         return $deleted;
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
         $dtos = [];
184 184
         /** @var NOSQLModelDto $dto */
185 185
         foreach ($data as &$insertData) {
186
-            if(is_object($insertData) && $insertData instanceof NOSQLModelDto) {
186
+            if (is_object($insertData) && $insertData instanceof NOSQLModelDto) {
187 187
                 $dto = clone $insertData;
188 188
             } else {
189 189
                 $dto = $this->getDtoCopy(true);
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
         foreach ($ids as $index => $insertedId) {
214 214
             $id = $insertedId->jsonSerialize();
215 215
             $dto = $dtos[$index];
216
-            if($dto instanceof  NOSQLModelDto) {
216
+            if ($dto instanceof  NOSQLModelDto) {
217 217
                 $dto->setPk($id['$oid']);
218 218
             } else {
219 219
 
Please login to merge, or discard this patch.