Completed
Pull Request — master (#2)
by
unknown
05:35
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.
src/NOSQL/Models/NOSQLQuery.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         $con = NOSQLParserTrait::initConnection($model, $con);
27 27
         $collection = $con->selectCollection($model->getSchema()->name);
28 28
         $result = $collection->findOne(['_id' => new ObjectId($pk)]);
29
-        if(null !== $result) {
29
+        if (null !== $result) {
30 30
             $model->feed($result->getArrayCopy());
31 31
         } else {
32 32
             throw new ApiException(t('Document not found'), 404);
@@ -53,21 +53,21 @@  discard block
 block discarded – undo
53 53
 
54 54
         $resultSet->count = $collection->countDocuments($filters, $nosqlOptions);
55 55
 
56
-        $nosqlOptions["limit"] = (integer)(array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50));
57
-        $page = (integer)(array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1);
56
+        $nosqlOptions["limit"] = (integer) (array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50));
57
+        $page = (integer) (array_key_exists(Api::API_PAGE_FIELD, $criteria) ? $criteria[Api::API_PAGE_FIELD] : 1);
58 58
         $nosqlOptions["skip"] = ($page === 1) ? 0 : ($page - 1) * $nosqlOptions["limit"];
59 59
 
60 60
         if ((array_key_exists(Api::API_ORDER_FIELD, $criteria)) && (is_array($criteria[Api::API_ORDER_FIELD]))) {
61 61
             $nosqlOptions["sort"] = [];
62 62
             foreach ($criteria[Api::API_ORDER_FIELD] as $field => $direction) {
63
-                $nosqlOptions["sort"][$field] = (abs($direction) === 1)  ? $direction : 1;
63
+                $nosqlOptions["sort"][$field] = (abs($direction) === 1) ? $direction : 1;
64 64
             }
65 65
         }
66 66
 
67 67
         $results = $collection->find($filters, $nosqlOptions);
68 68
         /** @var  $result */
69 69
         $items = $results->toArray();
70
-        foreach($items as $item) {
70
+        foreach ($items as $item) {
71 71
             $model->feed($item->getArrayCopy(), true);
72 72
             $resultSet->items[] = $model->getDtoCopy(true);
73 73
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         // Check index collation
97 97
         $options = [];
98 98
         $indexes = $collection->listIndexes();
99
-        foreach($indexes as $index) {
99
+        foreach ($indexes as $index) {
100 100
             $indexInfo = $index->__debugInfo();
101 101
             if (empty(array_diff(array_keys($index["key"]), array_keys($filters)))) {
102 102
                 if (array_key_exists("collation", $indexInfo)) {
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
         }
109 109
 
110 110
         if (array_key_exists("collation", $options)) {
111
-            foreach($filters as $key=>$filter) {
111
+            foreach ($filters as $key=>$filter) {
112 112
                 if (is_string($criteria[$key])) {
113 113
                     $filters[$key] = $criteria[$key];
114 114
                 }
@@ -147,9 +147,9 @@  discard block
 block discarded – undo
147 147
                         break;
148 148
                 }
149 149
             } elseif (NOSQLBase::NOSQL_TYPE_INTEGER === $property->type) {
150
-                $filterValue = (integer)$filterValue;
150
+                $filterValue = (integer) $filterValue;
151 151
             } else {
152
-                $filterValue = (float)$filterValue;
152
+                $filterValue = (float) $filterValue;
153 153
             }
154 154
             $filterValue = [
155 155
                 '$eq' => $filterValue,
Please login to merge, or discard this patch.
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.