Passed
Push — master ( 28a465...9f3368 )
by Fran
03:01
created
src/NOSQL/Services/NOSQLService.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
      */
56 56
     private function extractTypes() {
57 57
         $baseClass = new \ReflectionClass(NOSQLBase::class);
58
-        if(null !== $baseClass) {
58
+        if (null !== $baseClass) {
59 59
             $types = [];
60
-            foreach($baseClass->getConstants() as $constant) {
60
+            foreach ($baseClass->getConstants() as $constant) {
61 61
                 $types[] = $constant;
62 62
             }
63 63
             $this->setTypes($types);
@@ -79,10 +79,10 @@  discard block
 block discarded – undo
79 79
     public function getDomains() {
80 80
         $domains = [];
81 81
         $storedDomains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, TRUE);
82
-        if(!empty($storedDomains)) {
83
-            foreach($storedDomains as $domain => $data) {
82
+        if (!empty($storedDomains)) {
83
+            foreach ($storedDomains as $domain => $data) {
84 84
                 $domainLabel = str_replace(['@', '/'], '', $domain);
85
-                if('ROOT' !== $domainLabel) {
85
+                if ('ROOT' !== $domainLabel) {
86 86
                     $domains[] = $domainLabel;
87 87
                 }
88 88
             }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     public function getCollections($module) {
98 98
         $collections = [];
99 99
         $schemaFilename = CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
100
-        if(file_exists($schemaFilename)) {
100
+        if (file_exists($schemaFilename)) {
101 101
             $collections = $this->cache->getDataFromFile($schemaFilename, Cache::JSON, TRUE);
102 102
         }
103 103
         return $collections;
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
             '@NOSQL/generator/api.base.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Api' . DIRECTORY_SEPARATOR . 'base',
121 121
             '@NOSQL/generator/dto.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Dto' . DIRECTORY_SEPARATOR . 'Models',
122 122
         ];
123
-        foreach($collections as $raw) {
123
+        foreach ($collections as $raw) {
124 124
             $collection = new CollectionDto(false);
125 125
             $collection->fromArray($raw);
126
-            foreach($files as $template => $path) {
126
+            foreach ($files as $template => $path) {
127 127
                 GeneratorHelper::createDir($path);
128 128
                 $templateDump = $tpl->dump($template, [
129 129
                     'domain' => $module,
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
                     'properties' => $collection->properties,
132 132
                 ]);
133 133
                 $force = false;
134
-                if(false !== strpos($template, 'dto') || false !== strpos($template, 'base')) {
134
+                if (false !== strpos($template, 'dto') || false !== strpos($template, 'base')) {
135 135
                     $force = true;
136 136
                 }
137 137
                 $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force);
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         $db = ParserService::getInstance()->createConnection($module);
171 171
         $collections = $this->getCollections($module);
172 172
         $success = true;
173
-        foreach($collections as $raw) {
173
+        foreach ($collections as $raw) {
174 174
             $jsonSchema = $this->parseCollection($raw);
175 175
             try {
176 176
                 /** @var BSONDocument $result */
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
                 ]);
182 182
                 $response = $result->getArrayCopy();
183 183
                 $success = array_key_exists('ok', $response) && $response['ok'] > 0;
184
-            } catch(\Exception $exception) {
185
-                if($exception->getCode() !== 48) {
184
+            } catch (\Exception $exception) {
185
+                if ($exception->getCode() !== 48) {
186 186
                     $success = false;
187 187
                 }
188 188
             }
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
                     $property = new StringPropertyDto(false);
214 214
                     break;
215 215
             }
216
-            if(array_key_exists('type', $rawProperty)) {
216
+            if (array_key_exists('type', $rawProperty)) {
217 217
                 $property->bsonType = $rawProperty['type'];
218 218
             }
219
-            if(array_key_exists('description', $rawProperty)) {
219
+            if (array_key_exists('description', $rawProperty)) {
220 220
                 $property->description = $rawProperty['description'];
221 221
             }
222 222
             if (array_key_exists('required', $rawProperty) && $rawProperty['required']) {
Please login to merge, or discard this patch.
src/NOSQL/Models/NOSQLActiveRecord.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
      */
43 43
     public function getDtoCopy($cleanPk = false) {
44 44
         $copy = clone $this->dto;
45
-        if($cleanPk) {
45
+        if ($cleanPk) {
46 46
             $this->dto->resetPk();
47 47
         }
48 48
         return $copy;
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function save(Database $con = null) {
56 56
         $saved = false;
57
-        if(null === $con) {
57
+        if (null === $con) {
58 58
             $con = ParserService::getInstance()->createConnection($this->getDomain());
59 59
         }
60 60
         $collection = $con->selectCollection($this->getSchema()->name);
61 61
         try {
62 62
             $isInsert = $isUpdate = false;
63 63
             $this->dto->setLastUpdate(new \DateTime());
64
-            if($this->isNew()) {
64
+            if ($this->isNew()) {
65 65
                 $this->preInsert($con);
66 66
                 $isInsert = true;
67 67
             } elseif ($this->isModified()) {
@@ -69,17 +69,17 @@  discard block
 block discarded – undo
69 69
                 $isUpdate = true;
70 70
             }
71 71
             $result = $collection->insertOne($this->toArray());
72
-            if($result->getInsertedCount() > 0) {
72
+            if ($result->getInsertedCount() > 0) {
73 73
                 $id = $result->getInsertedId();
74 74
                 $this->dto->setPk($id->jsonSerialize()['$oid']);
75
-                if($isInsert) {
75
+                if ($isInsert) {
76 76
                     $this->postInsert($con);
77
-                } elseif($isUpdate) {
77
+                } elseif ($isUpdate) {
78 78
                     $this->postUpdate($con);
79 79
                 }
80 80
                 $saved = true;
81 81
             }
82
-        } catch(\Exception $exception) {
82
+        } catch (\Exception $exception) {
83 83
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
84 84
         }
85 85
         return $saved;
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function update(Database $con = null) {
93 93
         $updated = false;
94
-        if(null === $con) {
94
+        if (null === $con) {
95 95
             $con = ParserService::getInstance()->createConnection($this->getDomain());
96 96
         }
97 97
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
             $collection->findOneAndReplace(['_id' => new ObjectId($this->dto->getPk())], $data);
104 104
             $this->postUpdate($con);
105 105
             $updated = true;
106
-        } catch(\Exception $exception) {
106
+        } catch (\Exception $exception) {
107 107
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
108 108
         }
109 109
         return $updated;
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
      */
117 117
     public function bulkInsert(array $data, Database $con = null) {
118 118
         $inserts = 0;
119
-        if(null === $con) {
119
+        if (null === $con) {
120 120
             $con = ParserService::getInstance()->createConnection($this->getDomain());
121 121
         }
122 122
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
             $result = $collection->insertMany($data);
126 126
             $ids = $result->getInsertedIds();
127 127
             $inserts = $this->parseInsertedDtos($con, $ids, $dtos);
128
-        } catch(\Exception $exception) {
128
+        } catch (\Exception $exception) {
129 129
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
130 130
         }
131 131
         return $inserts;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
      */
138 138
     public function delete(Database $con = null) {
139 139
         $deleted = false;
140
-        if(null === $con) {
140
+        if (null === $con) {
141 141
             $con = ParserService::getInstance()->createConnection($this->getDomain());
142 142
         }
143 143
         $collection = $con->selectCollection($this->getSchema()->name);
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
             $this->postDelete($con);
148 148
             $deleted = true;
149 149
             $this->dto = null;
150
-        } catch(\Exception $exception) {
150
+        } catch (\Exception $exception) {
151 151
             Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray());
152 152
         }
153 153
         return $deleted;
Please login to merge, or discard this patch.