@@ -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,25 +64,25 @@ 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 | - switch(get_class($value)) { |
|
73 | + switch (get_class($value)) { |
|
74 | 74 | case UTCDateTime::class: |
75 | 75 | $value = $value->toDateTime()->format('Y-m-d H:i:s'); |
76 | 76 | break; |
77 | 77 | } |
78 | 78 | $this->$key = $value; |
79 | - if(in_array(strtolower($key), ['name', 'label', 'title', 'method'])) { |
|
79 | + if (in_array(strtolower($key), ['name', 'label', 'title', 'method'])) { |
|
80 | 80 | $name .= $sep . $value; |
81 | 81 | $sep = ' '; |
82 | 82 | } |
83 | 83 | } |
84 | 84 | } |
85 | - if($withName) { |
|
85 | + if ($withName) { |
|
86 | 86 | $this->dto->setName($name); |
87 | 87 | } |
88 | 88 | } |
@@ -56,7 +56,7 @@ |
||
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 | /** |
@@ -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; |
@@ -172,15 +172,15 @@ discard block |
||
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 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | $con = NOSQLParserTrait::initConnection($model, $con); |
22 | 22 | $collection = $con->selectCollection($model->getSchema()->name); |
23 | 23 | $result = $collection->findOne(['_id' => new ObjectId($pk)]); |
24 | - if(null !== $result) { |
|
24 | + if (null !== $result) { |
|
25 | 25 | $model->feed($result->getArrayCopy()); |
26 | 26 | } else { |
27 | 27 | throw new ApiException(t('Document not found'), 404); |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | $resultSet = new ResultsetDto(false); |
46 | 46 | $resultSet->count = $collection->countDocuments($filters); |
47 | 47 | $nosqlOptions = [ |
48 | - 'limit' => (integer)(array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)), |
|
48 | + 'limit' => (integer) (array_key_exists(Api::API_LIMIT_FIELD, $criteria) ? $criteria[Api::API_LIMIT_FIELD] : Config::getParam('pagination.limit', 50)), |
|
49 | 49 | ]; |
50 | 50 | $filters = self::parseCriteria($criteria, $model); |
51 | 51 | $results = $collection->find($filters, $nosqlOptions); |
52 | 52 | /** @var $result */ |
53 | 53 | $items = $results->toArray(); |
54 | - foreach($items as $item) { |
|
54 | + foreach ($items as $item) { |
|
55 | 55 | $model->feed($item->getArrayCopy(), true); |
56 | 56 | $resultSet->items[] = $model->getDtoCopy(true); |
57 | 57 | } |