@@ -143,6 +143,10 @@ discard block |
||
| 143 | 143 | return $errors; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | + /** |
|
| 147 | + * @param string $paramKey |
|
| 148 | + * @param boolean|null $paramValue |
|
| 149 | + */ |
|
| 146 | 150 | private function filterFields($resource, $paramKey, $paramValue, $checkParamValue = true) |
| 147 | 151 | { |
| 148 | 152 | $fields = []; |
@@ -158,6 +162,9 @@ discard block |
||
| 158 | 162 | return $fields; |
| 159 | 163 | } |
| 160 | 164 | |
| 165 | + /** |
|
| 166 | + * @param boolean $checkRequired |
|
| 167 | + */ |
|
| 161 | 168 | private function isMatchedValue($checkRequired, $value, $valueToMatch) |
| 162 | 169 | { |
| 163 | 170 | if (!$checkRequired) { |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | return $errors; |
| 109 | 109 | } |
| 110 | 110 | if (!empty($diff = array_diff($this->getRequiredFields($resource), array_keys(get_object_vars($resource))))) { |
| 111 | - array_walk($diff, function ($item, $key) use (&$errors) { |
|
| 111 | + array_walk($diff, function($item, $key) use (&$errors) { |
|
| 112 | 112 | $errors[$item] = 'Missing required field'; |
| 113 | 113 | }); |
| 114 | 114 | } |
@@ -26,8 +26,7 @@ discard block |
||
| 26 | 26 | if ((int)$res->hits() > 0) { |
| 27 | 27 | $results = json_decode($res->rawResponse())->results; |
| 28 | 28 | $message = $results[0]->{$this->primaryKey} === $this->getPrimaryKeyValue() ? |
| 29 | - 'Primary key collision' : |
|
| 30 | - 'Unique constraint violation'; |
|
| 29 | + 'Primary key collision' : 'Unique constraint violation'; |
|
| 31 | 30 | throw new RestException( |
| 32 | 31 | $message, |
| 33 | 32 | ['resourceName' => $this->resourceName, 'confilct' => $results[0]] |
@@ -39,13 +38,13 @@ discard block |
||
| 39 | 38 | private function getUniqueFieldQuery() |
| 40 | 39 | { |
| 41 | 40 | $uniqueFields = $this->getUniqueFields(); |
| 42 | - $query = $this->getClient()->database($this->getDatabaseName().'.'.$this->resourceName); |
|
| 41 | + $query = $this->getClient()->database($this->getDatabaseName() . '.' . $this->resourceName); |
|
| 43 | 42 | if ($this->isModification()) { |
| 44 | 43 | $uniqueFields = array_diff($uniqueFields, [$this->primaryKey]); |
| 45 | 44 | $query->where($this->primaryKey, '!=', $this->getPrimaryKeyValue()); |
| 46 | 45 | } |
| 47 | 46 | // @codeCoverageIgnoreStart |
| 48 | - $query->where(function ($query) use ($uniqueFields) { |
|
| 47 | + $query->where(function($query) use ($uniqueFields) { |
|
| 49 | 48 | foreach ($uniqueFields as $fieldName) { |
| 50 | 49 | if (property_exists($this->resource, $fieldName)) { |
| 51 | 50 | $query->orWhere($fieldName, '==', $this->resource->{$fieldName}); |
@@ -66,7 +65,7 @@ discard block |
||
| 66 | 65 | |
| 67 | 66 | public function query() |
| 68 | 67 | { |
| 69 | - $query = $this->getClient()->database($this->getDatabaseName().'.'.$this->resourceName); |
|
| 68 | + $query = $this->getClient()->database($this->getDatabaseName() . '.' . $this->resourceName); |
|
| 70 | 69 | return $query; |
| 71 | 70 | } |
| 72 | 71 | } |