@@ -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, |
@@ -24,7 +24,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 = str_replace(['set', 'Set', 'get', 'Get'], '', $name); |
| 50 | - if(false !== stripos($name, 'set')) { |
|
| 50 | + if (false !== stripos($name, 'set')) { |
|
| 51 | 51 | $this->$property = $arguments[0]; |
| 52 | 52 | } else { |
| 53 | 53 | return $this->$property; |
@@ -64,10 +64,10 @@ discard block |
||
| 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 | - } elseif($key === '_last_update') { |
|
| 70 | + } elseif ($key === '_last_update') { |
|
| 71 | 71 | $this->dto->setLastUpdate($value instanceof UTCDateTime ? $value : null); |
| 72 | 72 | } else { |
| 73 | 73 | if (is_object($value)) { |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | $this->$key = $value; |
| 81 | - if(in_array(strtolower($key), ['name', 'label', 'title', 'method'])) { |
|
| 81 | + if (in_array(strtolower($key), ['name', 'label', 'title', 'method'])) { |
|
| 82 | 82 | $name .= $sep . $value; |
| 83 | 83 | $sep = ' '; |
| 84 | 84 | } |
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | - if($withName) { |
|
| 87 | + if ($withName) { |
|
| 88 | 88 | $this->dto->setName($name); |
| 89 | 89 | } |
| 90 | 90 | } |
@@ -51,7 +51,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -175,16 +175,16 @@ discard block |
||
| 175 | 175 | if (!in_array($value, [true, false, 0, 1])) { |
| 176 | 176 | $errors[] = $property->getName(); |
| 177 | 177 | } |
| 178 | - $property->setValue($this, (bool)$value); |
|
| 178 | + $property->setValue($this, (bool) $value); |
|
| 179 | 179 | break; |
| 180 | 180 | case NOSQLBase::NOSQL_TYPE_DATE: |
| 181 | 181 | case NOSQLBase::NOSQL_TYPE_TIMESTAMP: |
| 182 | 182 | $dateTime = new \DateTime($value, new \DateTimeZone('UTC')); |
| 183 | - if(!$dateTime) { |
|
| 183 | + if (!$dateTime) { |
|
| 184 | 184 | $errors[] = $property->getName(); |
| 185 | 185 | } else { |
| 186 | 186 | $dateTime->setTimezone(new \DateTimeZone(date_default_timezone_get())); |
| 187 | - $property->setValue($this, new UTCDateTime($dateTime->getTimestamp()*1000)); |
|
| 187 | + $property->setValue($this, new UTCDateTime($dateTime->getTimestamp() * 1000)); |
|
| 188 | 188 | } |
| 189 | 189 | break; |
| 190 | 190 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function getDtoCopy($cleanPk = false) { |
| 45 | 45 | $copy = clone $this->dto; |
| 46 | - if($cleanPk) { |
|
| 46 | + if ($cleanPk) { |
|
| 47 | 47 | $this->dto->resetPk(); |
| 48 | 48 | } |
| 49 | 49 | return $copy; |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | */ |
| 60 | 60 | public function save(Database $con = null) { |
| 61 | 61 | $saved = false; |
| 62 | - if(null === $con) { |
|
| 62 | + if (null === $con) { |
|
| 63 | 63 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 64 | 64 | } |
| 65 | 65 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $isInsert = $isUpdate = false; |
| 68 | 68 | $this->prepareData(); |
| 69 | 69 | $this->dto->setLastUpdate(); |
| 70 | - if($this->isNew()) { |
|
| 70 | + if ($this->isNew()) { |
|
| 71 | 71 | $this->preInsert($con); |
| 72 | 72 | $isInsert = true; |
| 73 | 73 | } elseif ($this->isModified()) { |
@@ -75,19 +75,19 @@ discard block |
||
| 75 | 75 | $isUpdate = true; |
| 76 | 76 | } |
| 77 | 77 | $result = $collection->insertOne($this->toArray()); |
| 78 | - if($result->getInsertedCount() > 0) { |
|
| 78 | + if ($result->getInsertedCount() > 0) { |
|
| 79 | 79 | $id = $result->getInsertedId(); |
| 80 | 80 | $this->dto->setPk($id->jsonSerialize()['$oid']); |
| 81 | - if($isInsert) { |
|
| 81 | + if ($isInsert) { |
|
| 82 | 82 | $this->postInsert($con); |
| 83 | - } elseif($isUpdate) { |
|
| 83 | + } elseif ($isUpdate) { |
|
| 84 | 84 | $this->postUpdate($con); |
| 85 | 85 | } |
| 86 | 86 | $saved = true; |
| 87 | 87 | $this->countAction(); |
| 88 | 88 | } |
| 89 | - } catch(\Exception $exception) { |
|
| 90 | - if($exception instanceof NOSQLValidationException) { |
|
| 89 | + } catch (\Exception $exception) { |
|
| 90 | + if ($exception instanceof NOSQLValidationException) { |
|
| 91 | 91 | throw $exception; |
| 92 | 92 | } else { |
| 93 | 93 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function update(Database $con = null) { |
| 104 | 104 | $updated = false; |
| 105 | - if(null === $con) { |
|
| 105 | + if (null === $con) { |
|
| 106 | 106 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 107 | 107 | } |
| 108 | 108 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -116,8 +116,8 @@ discard block |
||
| 116 | 116 | $this->postUpdate($con); |
| 117 | 117 | $updated = true; |
| 118 | 118 | $this->countAction(); |
| 119 | - } catch(\Exception $exception) { |
|
| 120 | - if($exception instanceof NOSQLValidationException) { |
|
| 119 | + } catch (\Exception $exception) { |
|
| 120 | + if ($exception instanceof NOSQLValidationException) { |
|
| 121 | 121 | throw $exception; |
| 122 | 122 | } else { |
| 123 | 123 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | */ |
| 134 | 134 | public function bulkInsert(array $data, Database $con = null) { |
| 135 | 135 | $inserts = 0; |
| 136 | - if(null === $con) { |
|
| 136 | + if (null === $con) { |
|
| 137 | 137 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 138 | 138 | } |
| 139 | 139 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $ids = $result->getInsertedIds(); |
| 144 | 144 | $inserts = $this->parseInsertedDtos($con, $ids, $dtos); |
| 145 | 145 | $this->setActionCount($inserts); |
| 146 | - } catch(\Exception $exception) { |
|
| 146 | + } catch (\Exception $exception) { |
|
| 147 | 147 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 148 | 148 | } |
| 149 | 149 | return $inserts; |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | $upserts = 0; |
| 161 | 161 | $filters = $options = []; |
| 162 | 162 | |
| 163 | - if(null === $con) { |
|
| 163 | + if (null === $con) { |
|
| 164 | 164 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 165 | 165 | } |
| 166 | 166 | $collection = $con->selectCollection($this->getSchema()->name); |
| 167 | 167 | |
| 168 | - foreach($data as $item) { |
|
| 168 | + foreach ($data as $item) { |
|
| 169 | 169 | try { |
| 170 | 170 | $filters[$id] = ['$eq' => $item[$id]]; |
| 171 | 171 | $updateSet = []; |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function delete(Database $con = null) { |
| 193 | 193 | $deleted = false; |
| 194 | - if(null === $con) { |
|
| 194 | + if (null === $con) { |
|
| 195 | 195 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 196 | 196 | } |
| 197 | 197 | $collection = $con->selectCollection($this->getSchema()->name); |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $deleted = true; |
| 203 | 203 | $this->dto = null; |
| 204 | 204 | $this->countAction(); |
| 205 | - } catch(\Exception $exception) { |
|
| 205 | + } catch (\Exception $exception) { |
|
| 206 | 206 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 207 | 207 | } |
| 208 | 208 | return $deleted; |
@@ -216,14 +216,14 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function bulkDelete(array $filters, Database $con = null) { |
| 218 | 218 | $deletedCount = 0; |
| 219 | - if(null === $con) { |
|
| 219 | + if (null === $con) { |
|
| 220 | 220 | $con = ParserService::getInstance()->createConnection($this->getDomain()); |
| 221 | 221 | } |
| 222 | 222 | $collection = $con->selectCollection($this->getSchema()->name); |
| 223 | 223 | try { |
| 224 | 224 | $result = $collection->deleteMany($filters); |
| 225 | 225 | $deletedCount = $result->getDeletedCount(); |
| 226 | - } catch(\Exception $exception) { |
|
| 226 | + } catch (\Exception $exception) { |
|
| 227 | 227 | Logger::log($exception->getMessage(), LOG_CRIT, $this->toArray()); |
| 228 | 228 | } |
| 229 | 229 | return $deletedCount; |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | $dtos = []; |
| 241 | 241 | /** @var NOSQLModelDto $dto */ |
| 242 | 242 | foreach ($data as &$insertData) { |
| 243 | - if(is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
| 243 | + if (is_object($insertData) && $insertData instanceof NOSQLModelDto) { |
|
| 244 | 244 | $dto = clone $insertData; |
| 245 | 245 | } else { |
| 246 | 246 | $dto = $this->getDtoCopy(true); |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | foreach ($ids as $index => $insertedId) { |
| 271 | 271 | $id = $insertedId->jsonSerialize(); |
| 272 | 272 | $dto = $dtos[$index]; |
| 273 | - if($dto instanceof NOSQLModelDto) { |
|
| 273 | + if ($dto instanceof NOSQLModelDto) { |
|
| 274 | 274 | $dto->setPk($id['$oid']); |
| 275 | 275 | } else { |
| 276 | 276 | |