Completed
Push — master ( 64eab5...f30352 )
by Fran
02:01
created
src/NOSQL/Api/base/NOSQLBase.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
     public function getApi()
57 57
     {
58 58
         $class = explode('\\', get_called_class());
59
-        return $class[count($class)-1];
59
+        return $class[count($class) - 1];
60 60
     }
61 61
 
62 62
     /**
Please login to merge, or discard this patch.
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;
@@ -172,15 +172,15 @@  discard block
 block discarded – undo
172 172
                 if (!in_array($value, [true, false, 0, 1])) {
173 173
                     $errors[] = $property->getName();
174 174
                 }
175
-                $property->setValue($this, (bool)$value);
175
+                $property->setValue($this, (bool) $value);
176 176
                 break;
177 177
             case NOSQLBase::NOSQL_TYPE_DATE:
178 178
                 $dateTime = new \DateTime($value, new \DateTimeZone('UTC'));
179
-                if(!$dateTime) {
179
+                if (!$dateTime) {
180 180
                     $errors[] = $property->getName();
181 181
                 } else {
182 182
                     $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get()));
183
-                    $property->setValue($this, new UTCDateTime($dateTime->getTimestamp()*1000));
183
+                    $property->setValue($this, new UTCDateTime($dateTime->getTimestamp() * 1000));
184 184
                 }
185 185
                 break;
186 186
         }
Please login to merge, or discard this patch.
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
             }
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     public function getCollections($module) {
100 100
         $collections = [];
101 101
         $schemaFilename = CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Config' . DIRECTORY_SEPARATOR . 'schema.json';
102
-        if(file_exists($schemaFilename)) {
102
+        if (file_exists($schemaFilename)) {
103 103
             $collections = $this->cache->getDataFromFile($schemaFilename, Cache::JSON, TRUE);
104 104
         }
105 105
         return $collections;
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
             '@NOSQL/generator/api.base.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Api' . DIRECTORY_SEPARATOR . 'Base',
123 123
             '@NOSQL/generator/dto.php.twig' => CORE_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'Dto' . DIRECTORY_SEPARATOR . 'Models',
124 124
         ];
125
-        foreach($collections as $raw) {
125
+        foreach ($collections as $raw) {
126 126
             $collection = new CollectionDto(false);
127 127
             $collection->fromArray($raw);
128
-            foreach($files as $template => $path) {
128
+            foreach ($files as $template => $path) {
129 129
                 GeneratorHelper::createDir($path);
130 130
                 $templateDump = $tpl->dump($template, [
131 131
                     'domain' => $module,
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
                     'properties' => $collection->properties,
134 134
                 ]);
135 135
                 $force = false;
136
-                if(false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
136
+                if (false !== strpos($template, 'dto') || false !== strpos(strtolower($template), 'base')) {
137 137
                     $force = true;
138 138
                 }
139 139
                 $this->writeTemplateToFile($templateDump, $path . DIRECTORY_SEPARATOR . $collection->name . '.php', $force);
@@ -171,12 +171,12 @@  discard block
 block discarded – undo
171 171
         try {
172 172
             $collection = $db->selectCollection($collectionDto['name']);
173 173
             $textIndexes = [];
174
-            foreach($collectionDto['properties'] as $property) {
175
-                if(in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) {
174
+            foreach ($collectionDto['properties'] as $property) {
175
+                if (in_array($property['type'], [NOSQLBase::NOSQL_TYPE_STRING, NOSQLBase::NOSQL_TYPE_OBJECT])) {
176 176
                     $textIndexes[$property['name']] = 'text';
177 177
                 }
178 178
             }
179
-            if(count($textIndexes)) {
179
+            if (count($textIndexes)) {
180 180
                 $collection->createIndex($textIndexes, ['name' => 'idx_text_' . $collectionDto['name']]);
181 181
             }
182 182
         } catch (\Exception $exception) {
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         $db = ParserService::getInstance()->createConnection($module);
194 194
         $collections = $this->getCollections($module);
195 195
         $success = true;
196
-        foreach($collections as $raw) {
196
+        foreach ($collections as $raw) {
197 197
             $jsonSchema = $this->parseCollection($raw);
198 198
             try {
199 199
                 /** @var BSONDocument $result */
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
                 ]);
205 205
                 $response = $result->getArrayCopy();
206 206
                 $success = array_key_exists('ok', $response) && $response['ok'] > 0;
207
-            } catch(\Exception $exception) {
208
-                if($exception->getCode() !== 48) {
207
+            } catch (\Exception $exception) {
208
+                if ($exception->getCode() !== 48) {
209 209
                     $success = false;
210 210
                 }
211 211
             }
@@ -237,10 +237,10 @@  discard block
 block discarded – undo
237 237
                     $property = new StringPropertyDto(false);
238 238
                     break;
239 239
             }
240
-            if(array_key_exists('type', $rawProperty)) {
240
+            if (array_key_exists('type', $rawProperty)) {
241 241
                 $property->bsonType = $rawProperty['type'];
242 242
             }
243
-            if(array_key_exists('description', $rawProperty)) {
243
+            if (array_key_exists('description', $rawProperty)) {
244 244
                 $property->description = $rawProperty['description'];
245 245
             }
246 246
             if (array_key_exists('required', $rawProperty) && $rawProperty['required']) {
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
     public function getValidations() {
259 259
         $fieldTypes = new \ReflectionClass(Field::class);
260 260
         $validations = [];
261
-        foreach($fieldTypes->getConstants() as $validation) {
261
+        foreach ($fieldTypes->getConstants() as $validation) {
262 262
             $validations[] = $validation;
263 263
         }
264 264
         return $validations;
Please login to merge, or discard this patch.
src/NOSQL/Models/NOSQLQuery.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
         $con = NOSQLParserTrait::initConnection($model, $con);
23 23
         $collection = $con->selectCollection($model->getSchema()->name);
24 24
         $result = $collection->findOne(['_id' => new ObjectId($pk)]);
25
-        if(null !== $result) {
25
+        if (null !== $result) {
26 26
             $model->feed($result->getArrayCopy());
27 27
         } else {
28 28
             throw new ApiException(t('Document not found'), 404);
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
         $filters = self::parseCriteria($criteria, $model);
49 49
         $resultSet->count = $collection->countDocuments($filters);
50 50
         $nosqlOptions = [
51
-            'limit' => (integer)(array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)),
51
+            'limit' => (integer) (array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)),
52 52
         ];
53 53
         $results = $collection->find($filters, $nosqlOptions);
54 54
         /** @var  $result */
55 55
         $items = $results->toArray();
56
-        foreach($items as $item) {
56
+        foreach ($items as $item) {
57 57
             $model->feed($item->getArrayCopy(), true);
58 58
             $resultSet->items[] = $model->getDtoCopy(true);
59 59
         }
@@ -107,9 +107,9 @@  discard block
 block discarded – undo
107 107
                         break;
108 108
                 }
109 109
             } elseif (NOSQLBase::NOSQL_TYPE_INTEGER === $property->type) {
110
-                $filterValue = (integer)$filterValue;
110
+                $filterValue = (integer) $filterValue;
111 111
             } else {
112
-                $filterValue = (float)$filterValue;
112
+                $filterValue = (float) $filterValue;
113 113
             }
114 114
             $filterValue = [
115 115
                 '$eq' => $filterValue,
Please login to merge, or discard this patch.