Passed
Push — master ( 35d9b5...32969b )
by Fran
02:26
created
src/NOSQL/Services/NOSQLService.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
      */
58 58
     private function extractTypes() {
59 59
         $baseClass = new \ReflectionClass(NOSQLBase::class);
60
-        if(null !== $baseClass) {
60
+        if (null !== $baseClass) {
61 61
             $types = [];
62
-            foreach($baseClass->getConstants() as $constant) {
62
+            foreach ($baseClass->getConstants() as $constant) {
63 63
                 $types[] = $constant;
64 64
             }
65 65
             $this->setTypes($types);
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
     public function getDomains() {
82 82
         $domains = [];
83 83
         $storedDomains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json', Cache::JSON, TRUE);
84
-        if(!empty($storedDomains)) {
85
-            foreach($storedDomains as $domain => $data) {
84
+        if (!empty($storedDomains)) {
85
+            foreach ($storedDomains as $domain => $data) {
86 86
                 $domainLabel = str_replace(['@', '/'], '', $domain);
87
-                if('ROOT' !== $domainLabel) {
87
+                if ('ROOT' !== $domainLabel) {
88 88
                     $domains[] = $domainLabel;
89 89
                 }
90 90
             }
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
         $collections = [];
101 101
         $path = GeneratorHelper::getDomainPaths($module);
102 102
         $schemaFilename = $path['base'] . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
103
-        if(file_exists($schemaFilename)) {
103
+        if (file_exists($schemaFilename)) {
104 104
             $collections = $this->cache->getDataFromFile($schemaFilename, Cache::JSON, TRUE);
105 105
         }
106 106
         return $collections;
@@ -123,10 +123,10 @@  discard block
 block discarded – undo
123 123
             '@NOSQL/generator/api.base.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Api' . DIRECTORY_SEPARATOR . 'Base',
124 124
             '@NOSQL/generator/dto.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Dto' . DIRECTORY_SEPARATOR . 'Models',
125 125
         ];
126
-        foreach($collections as $raw) {
126
+        foreach ($collections as $raw) {
127 127
             $collection = new CollectionDto(false);
128 128
             $collection->fromArray($raw);
129
-            foreach($files as $template => $path) {
129
+            foreach ($files as $template => $path) {
130 130
                 GeneratorHelper::createDir($path);
131 131
                 $templateDump = $tpl->dump($template, [
132 132
                     'domain' => $module,
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                     'properties' => $collection->properties,
135 135
                 ]);
136 136
                 $force = false;
137
-                if(false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
137
+                if (false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
138 138
                     $force = true;
139 139
                 }
140 140
                 $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force);
@@ -172,12 +172,12 @@  discard block
 block discarded – undo
172 172
         try {
173 173
             $collection = $db->selectCollection($collectionDto['name']);
174 174
             $textIndexes = [];
175
-            foreach($collectionDto['properties'] as $property) {
176
-                if(in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) {
175
+            foreach ($collectionDto['properties'] as $property) {
176
+                if (in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) {
177 177
                     $textIndexes[$property['name']] = 'text';
178 178
                 }
179 179
             }
180
-            if(count($textIndexes)) {
180
+            if (count($textIndexes)) {
181 181
                 $collection->createIndex($textIndexes, ['name' => 'idx_text_' . $collectionDto['name']]);
182 182
             }
183 183
         } catch (\Exception $exception) {
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
         $db = ParserService::getInstance()->createConnection($module);
195 195
         $collections = $this->getCollections($module);
196 196
         $success = true;
197
-        foreach($collections as $raw) {
197
+        foreach ($collections as $raw) {
198 198
             $jsonSchema = $this->parseCollection($raw);
199 199
             try {
200 200
                 /** @var BSONDocument $result */
@@ -205,8 +205,8 @@  discard block
 block discarded – undo
205 205
                 ]);
206 206
                 $response = $result->getArrayCopy();
207 207
                 $success = array_key_exists('ok', $response) && $response['ok'] > 0;
208
-            } catch(\Exception $exception) {
209
-                if($exception->getCode() !== 48) {
208
+            } catch (\Exception $exception) {
209
+                if ($exception->getCode() !== 48) {
210 210
                     $success = false;
211 211
                 }
212 212
             }
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
                     $property = new StringPropertyDto(false);
239 239
                     break;
240 240
             }
241
-            if(array_key_exists('type', $rawProperty)) {
241
+            if (array_key_exists('type', $rawProperty)) {
242 242
                 $property->bsonType = $rawProperty['type'];
243 243
             }
244
-            if(array_key_exists('description', $rawProperty)) {
244
+            if (array_key_exists('description', $rawProperty)) {
245 245
                 $property->description = $rawProperty['description'];
246 246
             }
247 247
             if (array_key_exists('required', $rawProperty) && $rawProperty['required']) {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     public function getValidations() {
260 260
         $fieldTypes = new \ReflectionClass(Field::class);
261 261
         $validations = [];
262
-        foreach($fieldTypes->getConstants() as $validation) {
262
+        foreach ($fieldTypes->getConstants() as $validation) {
263 263
             $validations[] = $validation;
264 264
         }
265 265
         return $validations;
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
@@ -73,18 +73,18 @@
 block discarded – undo
73 73
      * @throws \PSFS\base\exception\GeneratorException
74 74
      */
75 75
     protected function hydrate() {
76
-        if(empty($this->domain)) {
76
+        if (empty($this->domain)) {
77 77
             throw new NOSQLParserException(t('Domain not defined'), NOSQLParserException::NOSQL_PARSER_DOMAIN_NOT_DEFINED);
78 78
         }
79 79
         $paths = GeneratorHelper::getDomainPaths($this->domain);
80 80
         $schemaFilename = $paths['base'] . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
81
-        if(file_exists($schemaFilename)) {
81
+        if (file_exists($schemaFilename)) {
82 82
             $schema = Cache::getInstance()->getDataFromFile($schemaFilename, Cache::JSON, true);
83 83
             $class = get_called_class();
84 84
             $this->schema = new CollectionDto(false);
85
-            foreach($schema as $collection) {
85
+            foreach ($schema as $collection) {
86 86
                 $collectionName = $collection['name'];
87
-                if(false !== strpos($class, $collectionName)) {
87
+                if (false !== strpos($class, $collectionName)) {
88 88
                     $this->schema->fromArray($collection);
89 89
                     break;
90 90
                 }
Please login to merge, or discard this patch.