@@ -57,9 +57,9 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -22,7 +22,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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, |