Passed
Push — master ( 92ccf2...d75410 )
by Fran
03:08
created
src/NOSQL/Models/base/NOSQLModelTrait.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
     public function __get($name)
25 25
     {
26 26
         $value = null;
27
-        if(null !== $this->dto && property_exists($this->dto, $name)) {
27
+        if (null !== $this->dto && property_exists($this->dto, $name)) {
28 28
             $value = $this->dto->$name;
29 29
         }
30 30
         return $value;
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function __set($name, $value)
38 38
     {
39
-        if(null !== $this->dto && property_exists($this->dto, $name)) {
39
+        if (null !== $this->dto && property_exists($this->dto, $name)) {
40 40
             $this->dto->$name = $value;
41 41
             $this->addChanges($name);
42 42
         }
@@ -45,9 +45,9 @@  discard block
 block discarded – undo
45 45
 
46 46
     public function __call($name, $arguments)
47 47
     {
48
-        if(preg_match('/^(set|get)/', $name)) {
48
+        if (preg_match('/^(set|get)/', $name)) {
49 49
             $property = strtolower(str_replace(['set', 'Set', 'get', 'Get'], '', $name));
50
-            if(false !== stripos($name, 'set')) {
50
+            if (false !== stripos($name, 'set')) {
51 51
                 $this->dto->$property = $arguments[0];
52 52
             } else {
53 53
                 return $this->dto->$property;
@@ -64,11 +64,11 @@  discard block
 block discarded – undo
64 64
     public function feed(array $data, $withName = false) {
65 65
         $name = '';
66 66
         $sep = '';
67
-        foreach($data as $key => $value) {
68
-            if($value instanceof ObjectId) {
67
+        foreach ($data as $key => $value) {
68
+            if ($value instanceof ObjectId) {
69 69
                 $this->dto->setPk($value->jsonSerialize()['$oid']);
70 70
                 $name = $this->dto->getPk();
71
-            } elseif($key === '_last_update') {
71
+            } elseif ($key === '_last_update') {
72 72
                 $this->dto->setLastUpdate($value instanceof UTCDateTime ? $value : null);
73 73
             } else {
74 74
                 if (is_object($value)) {
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
                     }
80 80
                 }
81 81
                 $this->$key = $value;
82
-                if(in_array(strtolower($key), ['name', 'label', 'title', 'method'])) {
82
+                if (in_array(strtolower($key), ['name', 'label', 'title', 'method'])) {
83 83
                     $name .= $sep . $value;
84 84
                     $sep = ' ';
85 85
                 }
86 86
             }
87 87
         }
88
-        if($withName) {
88
+        if ($withName) {
89 89
             $this->dto->setName($name);
90 90
         }
91 91
     }
Please login to merge, or discard this patch.
src/NOSQL/Models/base/NOSQLParserTrait.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -74,18 +74,18 @@
 block discarded – undo
74 74
      * @throws \PSFS\base\exception\GeneratorException
75 75
      */
76 76
     protected function hydrate() {
77
-        if(empty($this->domain)) {
77
+        if (empty($this->domain)) {
78 78
             throw new NOSQLParserException(t('Domain not defined'), NOSQLParserException::NOSQL_PARSER_DOMAIN_NOT_DEFINED);
79 79
         }
80 80
         $paths = NOSQLService::getDomainPaths($this->domain);
81 81
         $schemaFilename = $paths['base'] . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
82
-        if(file_exists($schemaFilename)) {
82
+        if (file_exists($schemaFilename)) {
83 83
             $schema = Cache::getInstance()->getDataFromFile($schemaFilename, Cache::JSON, true);
84 84
             $class = get_called_class();
85 85
             $this->schema = new CollectionDto(false);
86
-            foreach($schema as $collection) {
86
+            foreach ($schema as $collection) {
87 87
                 $collectionName = $collection['name'];
88
-                if(false !== strpos($class, $collectionName)) {
88
+                if (false !== strpos($class, $collectionName)) {
89 89
                     $this->schema->fromArray($collection);
90 90
                     break;
91 91
                 }
Please login to merge, or discard this patch.
src/NOSQL/Services/NOSQLService.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
      */
62 62
     private function extractTypes() {
63 63
         $baseClass = new \ReflectionClass(NOSQLBase::class);
64
-        if(null !== $baseClass) {
64
+        if (null !== $baseClass) {
65 65
             $types = [];
66
-            foreach($baseClass->getConstants() as $constant) {
66
+            foreach ($baseClass->getConstants() as $constant) {
67 67
                 $types[] = $constant;
68 68
             }
69 69
             $this->setTypes($types);
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
     public function getDomains() {
86 86
         $domains = [];
87 87
         $storedDomains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, TRUE);
88
-        if(!empty($storedDomains)) {
89
-            foreach($storedDomains as $domain => $data) {
88
+        if (!empty($storedDomains)) {
89
+            foreach ($storedDomains as $domain => $data) {
90 90
                 $domainLabel = str_replace(['@', '/'], '', $domain);
91
-                if('ROOT' !== $domainLabel) {
91
+                if ('ROOT' !== $domainLabel) {
92 92
                     $domains[] = $domainLabel;
93 93
                 }
94 94
             }
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
     public static function getDomainPaths($module) {
100 100
         $domains = Router::getInstance()->getDomains();
101 101
         $path = null;
102
-        foreach($domains as $domain => $paths) {
103
-            if(preg_match("/^@" . $module . "\//i", $domain)) {
102
+        foreach ($domains as $domain => $paths) {
103
+            if (preg_match("/^@" . $module . "\//i", $domain)) {
104 104
                 $path = $paths;
105 105
                 break;
106 106
             }
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
     public function getCollections($module) {
116 116
         $collections = [];
117 117
         $path = self::getDomainPaths($module);
118
-        if(null === $path) {
118
+        if (null === $path) {
119 119
             throw new ApiException(t("Module not found"), 404);
120 120
         }
121 121
         $schemaFilename = $path['base'] . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
122
-        if(file_exists($schemaFilename)) {
122
+        if (file_exists($schemaFilename)) {
123 123
             $collections = $this->cache->getDataFromFile($schemaFilename, Cache::JSON, TRUE);
124 124
         }
125 125
         return $collections;
@@ -142,10 +142,10 @@  discard block
 block discarded – undo
142 142
             '@NOSQL/generator/api.base.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Api' . DIRECTORY_SEPARATOR . 'Base',
143 143
             '@NOSQL/generator/dto.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Dto' . DIRECTORY_SEPARATOR . 'Models',
144 144
         ];
145
-        foreach($collections as $raw) {
145
+        foreach ($collections as $raw) {
146 146
             $collection = new CollectionDto(false);
147 147
             $collection->fromArray($raw);
148
-            foreach($files as $template => $path) {
148
+            foreach ($files as $template => $path) {
149 149
                 GeneratorHelper::createDir($path);
150 150
                 $templateDump = $tpl->dump($template, [
151 151
                     'domain' => $module,
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                     'properties' => $collection->properties,
154 154
                 ]);
155 155
                 $force = false;
156
-                if(false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
156
+                if (false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
157 157
                     $force = true;
158 158
                 }
159 159
                 $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force);
@@ -191,12 +191,12 @@  discard block
 block discarded – undo
191 191
         try {
192 192
             $collection = $db->selectCollection($collectionDto['name']);
193 193
             $textIndexes = [];
194
-            foreach($collectionDto['properties'] as $property) {
195
-                if(in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) {
194
+            foreach ($collectionDto['properties'] as $property) {
195
+                if (in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) {
196 196
                     $textIndexes[$property['name']] = 'text';
197 197
                 }
198 198
             }
199
-            if(count($textIndexes)) {
199
+            if (count($textIndexes)) {
200 200
                 $collection->createIndex($textIndexes, ['name' => 'idx_text_' . $collectionDto['name']]);
201 201
             }
202 202
         } catch (\Exception $exception) {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
         $db = ParserService::getInstance()->createConnection($module);
214 214
         $collections = $this->getCollections($module);
215 215
         $success = true;
216
-        foreach($collections as $raw) {
216
+        foreach ($collections as $raw) {
217 217
             $jsonSchema = $this->parseCollection($raw);
218 218
             try {
219 219
                 /** @var BSONDocument $result */
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
                 ]);
225 225
                 $response = $result->getArrayCopy();
226 226
                 $success = array_key_exists('ok', $response) && $response['ok'] > 0;
227
-            } catch(\Exception $exception) {
228
-                if($exception->getCode() !== 48) {
227
+            } catch (\Exception $exception) {
228
+                if ($exception->getCode() !== 48) {
229 229
                     $success = false;
230 230
                 }
231 231
             }
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
                     $property = new StringPropertyDto(false);
260 260
                     break;
261 261
             }
262
-            if(array_key_exists('type', $rawProperty)) {
262
+            if (array_key_exists('type', $rawProperty)) {
263 263
                 $property->bsonType = $rawProperty['type'];
264 264
             }
265
-            if(array_key_exists('description', $rawProperty)) {
265
+            if (array_key_exists('description', $rawProperty)) {
266 266
                 $property->description = $rawProperty['description'];
267 267
             }
268 268
             if (array_key_exists('required', $rawProperty) && $rawProperty['required']) {
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
     public function getValidations() {
281 281
         $fieldTypes = new \ReflectionClass(Field::class);
282 282
         $validations = [];
283
-        foreach($fieldTypes->getConstants() as $validation) {
283
+        foreach ($fieldTypes->getConstants() as $validation) {
284 284
             $validations[] = $validation;
285 285
         }
286 286
         return $validations;
Please login to merge, or discard this patch.
src/NOSQL/Models/NOSQLActiveRecord.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public function getDtoCopy($cleanPk = false) {
46 46
         $copy = clone $this->dto;
47
-        if($cleanPk) {
47
+        if ($cleanPk) {
48 48
             $this->dto->resetPk();
49 49
         }
50 50
         return $copy;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function save(Database $con = null) {
62 62
         $saved = false;
63
-        if(null === $con) {
63
+        if (null === $con) {
64 64
             $con = ParserService::getInstance()->createConnection($this->getDomain());
65 65
         }
66 66
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
             $isInsert = $isUpdate = false;
69 69
             $this->prepareData();
70 70
             $this->dto->setLastUpdate();
71
-            if($this->isNew()) {
71
+            if ($this->isNew()) {
72 72
                 $this->preInsert($con);
73 73
                 $isInsert = true;
74 74
             } elseif ($this->isModified()) {
@@ -76,19 +76,19 @@  discard block
 block discarded – undo
76 76
                 $isUpdate = true;
77 77
             }
78 78
             $result = $collection->insertOne($this->toArray());
79
-            if($result->getInsertedCount() > 0) {
79
+            if ($result->getInsertedCount() > 0) {
80 80
                 $id = $result->getInsertedId();
81 81
                 $this->dto->setPk($id->jsonSerialize()['$oid']);
82
-                if($isInsert) {
82
+                if ($isInsert) {
83 83
                     $this->postInsert($con);
84
-                } elseif($isUpdate) {
84
+                } elseif ($isUpdate) {
85 85
                     $this->postUpdate($con);
86 86
                 }
87 87
                 $saved = true;
88 88
                 $this->countAction();
89 89
             }
90
-        } catch(\Exception $exception) {
91
-            if($exception instanceof NOSQLValidationException) {
90
+        } catch (\Exception $exception) {
91
+            if ($exception instanceof NOSQLValidationException) {
92 92
                 throw $exception;
93 93
             } else {
94 94
                 Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     public function update(Database $con = null) {
105 105
         $updated = false;
106
-        if(null === $con) {
106
+        if (null === $con) {
107 107
             $con = ParserService::getInstance()->createConnection($this->getDomain());
108 108
         }
109 109
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
             $this->postUpdate($con);
118 118
             $updated = true;
119 119
             $this->countAction();
120
-        } catch(\Exception $exception) {
121
-            if($exception instanceof NOSQLValidationException) {
120
+        } catch (\Exception $exception) {
121
+            if ($exception instanceof NOSQLValidationException) {
122 122
                 throw $exception;
123 123
             } else {
124 124
                 Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     public function bulkInsert(array $data, Database $con = null) {
136 136
         $inserts = 0;
137
-        if(null === $con) {
137
+        if (null === $con) {
138 138
             $con = ParserService::getInstance()->createConnection($this->getDomain());
139 139
         }
140 140
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
             $ids = $result->getInsertedIds();
145 145
             $inserts = $this->parseInsertedDtos($con, $ids, $dtos);
146 146
             $this->setActionCount($inserts);
147
-        } catch(\Exception $exception) {
147
+        } catch (\Exception $exception) {
148 148
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
149 149
         }
150 150
         return $inserts;
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      * @return int
159 159
      */
160 160
     public function bulkUpsert(array $data, $id, Database $con = null) {
161
-        if(null === $con) {
161
+        if (null === $con) {
162 162
             $con = ParserService::getInstance()->createConnection($this->getDomain());
163 163
         }
164 164
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
         try {
169 169
             // Check index collation
170 170
             $indexes = $collection->listIndexes();
171
-            foreach($indexes as $index) {
171
+            foreach ($indexes as $index) {
172 172
                 $indexInfo = $index->__debugInfo();
173 173
                 $keys = array_keys($index["key"]);
174 174
                 if ((count($keys) === 1) && ($keys[0] === $id) && (array_key_exists("collation", $indexInfo))) {
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
                 }
179 179
             }
180 180
 
181
-            foreach($data as $item) {
181
+            foreach ($data as $item) {
182 182
                 $filter[$id] = ['$eq' => $item[$id]];
183 183
                 $update = [];
184 184
                 $update['$set'] = $item;
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
      */
205 205
     public function delete(Database $con = null) {
206 206
         $deleted = false;
207
-        if(null === $con) {
207
+        if (null === $con) {
208 208
             $con = ParserService::getInstance()->createConnection($this->getDomain());
209 209
         }
210 210
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
             $deleted = true;
216 216
             $this->dto = null;
217 217
             $this->countAction();
218
-        } catch(\Exception $exception) {
218
+        } catch (\Exception $exception) {
219 219
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
220 220
         }
221 221
         return $deleted;
@@ -229,14 +229,14 @@  discard block
 block discarded – undo
229 229
      */
230 230
     public function bulkDelete(array $filters, Database $con = null) {
231 231
         $deletedCount = 0;
232
-        if(null === $con) {
232
+        if (null === $con) {
233 233
             $con = ParserService::getInstance()->createConnection($this->getDomain());
234 234
         }
235 235
         $collection = $con->selectCollection($this->getSchema()->name);
236 236
         try {
237 237
             $result = $collection->deleteMany($filters);
238 238
             $deletedCount = $result->getDeletedCount();
239
-        } catch(\Exception $exception) {
239
+        } catch (\Exception $exception) {
240 240
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
241 241
         }
242 242
         return $deletedCount;
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         $dtos = [];
254 254
         /** @var NOSQLModelDto $dto */
255 255
         foreach ($data as &$insertData) {
256
-            if(is_object($insertData) && $insertData instanceof NOSQLModelDto) {
256
+            if (is_object($insertData) && $insertData instanceof NOSQLModelDto) {
257 257
                 $dto = clone $insertData;
258 258
             } else {
259 259
                 $dto = $this->getDtoCopy(true);
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         foreach ($ids as $index => $insertedId) {
284 284
             $id = is_string($insertedId) ? ['$oid' => $insertedId] : $insertedId->jsonSerialize();
285 285
             $dto = $dtos[$index];
286
-            if($dto instanceof  NOSQLModelDto) {
286
+            if ($dto instanceof  NOSQLModelDto) {
287 287
                 $dto->setPk($id['$oid']);
288 288
             } else {
289 289
 
Please login to merge, or discard this patch.