@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function setIndex($index) |
| 84 | 84 | { |
| 85 | - $this->index = (string)$index; |
|
| 85 | + $this->index = (string) $index; |
|
| 86 | 86 | return $this; |
| 87 | 87 | } |
| 88 | 88 | |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | */ |
| 94 | 94 | public function setType($type) |
| 95 | 95 | { |
| 96 | - $this->type = (string)$type; |
|
| 96 | + $this->type = (string) $type; |
|
| 97 | 97 | return $this; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/5.0/search-request-script-fields.html |
| 126 | 126 | * @return self $this |
| 127 | 127 | */ |
| 128 | - public function addScriptField($fieldName, $script, array $params=null, $lang='painless') |
|
| 128 | + public function addScriptField($fieldName, $script, array $params = null, $lang = 'painless') |
|
| 129 | 129 | { |
| 130 | 130 | $item = [ |
| 131 | 131 | 'script' => [ |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | 'inline' => $script, |
| 134 | 134 | ] |
| 135 | 135 | ]; |
| 136 | - if ( $params ) { |
|
| 136 | + if ($params) { |
|
| 137 | 137 | $item['script']['params'] = $params; |
| 138 | 138 | } |
| 139 | 139 | $this->scriptFields[$fieldName] = $item; |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-range-query.html |
| 217 | 217 | * @return $this; |
| 218 | 218 | */ |
| 219 | - public function whereBetween($field, $min, $max, $dateFormat=null) |
|
| 219 | + public function whereBetween($field, $min, $max, $dateFormat = null) |
|
| 220 | 220 | { |
| 221 | 221 | $params = ['gte' => $min, 'lte' => $max]; |
| 222 | 222 | if ($dateFormat) { |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-script-query.html |
| 241 | 241 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/5.0/modules-scripting-painless.html |
| 242 | 242 | */ |
| 243 | - public function whereScript($script, array $params=null, $lang='painless') |
|
| 243 | + public function whereScript($script, array $params = null, $lang = 'painless') |
|
| 244 | 244 | { |
| 245 | 245 | $item = [ |
| 246 | 246 | 'script' => [ |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | ] |
| 251 | 251 | ] |
| 252 | 252 | ]; |
| 253 | - if ( $params ) { |
|
| 253 | + if ($params) { |
|
| 254 | 254 | $item['script']['script']['params'] = $params; |
| 255 | 255 | } |
| 256 | 256 | $this->filters[] = $item; |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * @param null $dateFormat |
| 265 | 265 | * @return $this |
| 266 | 266 | */ |
| 267 | - public function whereGreaterOrEqual($field, $value, $dateFormat=null) |
|
| 267 | + public function whereGreaterOrEqual($field, $value, $dateFormat = null) |
|
| 268 | 268 | { |
| 269 | 269 | $params = ['gte' => $value]; |
| 270 | 270 | if ($dateFormat) { |
@@ -281,7 +281,7 @@ discard block |
||
| 281 | 281 | * @param null $dateFormat |
| 282 | 282 | * @return $this |
| 283 | 283 | */ |
| 284 | - public function whereGreater($field, $value, $dateFormat=null) |
|
| 284 | + public function whereGreater($field, $value, $dateFormat = null) |
|
| 285 | 285 | { |
| 286 | 286 | $params = ['gt' => $value]; |
| 287 | 287 | if ($dateFormat) { |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @param null $dateFormat |
| 299 | 299 | * @return $this |
| 300 | 300 | */ |
| 301 | - public function whereLessOrEqual($field, $value, $dateFormat=null) |
|
| 301 | + public function whereLessOrEqual($field, $value, $dateFormat = null) |
|
| 302 | 302 | { |
| 303 | 303 | $params = ['lte' => $value]; |
| 304 | 304 | if ($dateFormat) { |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @param null $dateFormat |
| 316 | 316 | * @return $this |
| 317 | 317 | */ |
| 318 | - public function whereLess($field, $value, $dateFormat=null) |
|
| 318 | + public function whereLess($field, $value, $dateFormat = null) |
|
| 319 | 319 | { |
| 320 | 320 | $params = ['lt' => $value]; |
| 321 | 321 | if ($dateFormat) { |
@@ -351,10 +351,10 @@ discard block |
||
| 351 | 351 | * @example $q->addOrderBy('channel', 'asc')->addOrderBy('_score', 'desc'); |
| 352 | 352 | * @return $this |
| 353 | 353 | */ |
| 354 | - public function addOrderBy($field, $order='asc') |
|
| 354 | + public function addOrderBy($field, $order = 'asc') |
|
| 355 | 355 | { |
| 356 | - $field = (string)$field; |
|
| 357 | - $order = (string)$order; |
|
| 356 | + $field = (string) $field; |
|
| 357 | + $order = (string) $order; |
|
| 358 | 358 | $this->orders[] = [$field => ['order' => $order]]; |
| 359 | 359 | return $this; |
| 360 | 360 | } |
@@ -365,10 +365,10 @@ discard block |
||
| 365 | 365 | * @param int $offset - сколько строк пропустить |
| 366 | 366 | * @return $this; |
| 367 | 367 | */ |
| 368 | - public function limit($limit, $offset=0) |
|
| 368 | + public function limit($limit, $offset = 0) |
|
| 369 | 369 | { |
| 370 | - $this->limit = (int)$limit; |
|
| 371 | - $this->offset = (int)$offset; |
|
| 370 | + $this->limit = (int) $limit; |
|
| 371 | + $this->offset = (int) $offset; |
|
| 372 | 372 | return $this; |
| 373 | 373 | } |
| 374 | 374 | |
@@ -389,9 +389,9 @@ discard block |
||
| 389 | 389 | $this->totalResults = $result['total']; // total results |
| 390 | 390 | foreach ($result['hits'] as $hit) { |
| 391 | 391 | $row = $hit['_source']; |
| 392 | - if ( isset($hit['fields']) ) { // script fields |
|
| 392 | + if (isset($hit['fields'])) { // script fields |
|
| 393 | 393 | foreach ($hit['fields'] as $field => $data) { |
| 394 | - if ( count($data) == 1 ) { |
|
| 394 | + if (count($data) == 1) { |
|
| 395 | 395 | $row[$field] = array_shift($data); |
| 396 | 396 | } |
| 397 | 397 | else { |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | public function fetchOne() |
| 415 | 415 | { |
| 416 | 416 | $results = $this->fetchAll(); |
| 417 | - if ( count($results) ) { |
|
| 417 | + if (count($results)) { |
|
| 418 | 418 | return array_shift($results); |
| 419 | 419 | } |
| 420 | 420 | else { |
@@ -453,23 +453,23 @@ discard block |
||
| 453 | 453 | 'from' => $this->offset |
| 454 | 454 | ]; |
| 455 | 455 | |
| 456 | - if ( $this->orders ) { |
|
| 456 | + if ($this->orders) { |
|
| 457 | 457 | $params['body']['sort'] = $this->orders; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - if ( $this->includes ) { |
|
| 460 | + if ($this->includes) { |
|
| 461 | 461 | $params['body']['_source']['includes'] = $this->includes; |
| 462 | 462 | } |
| 463 | 463 | |
| 464 | - if ( $this->excludes ) { |
|
| 464 | + if ($this->excludes) { |
|
| 465 | 465 | $params['body']['_source']['excludes'] = $this->excludes; |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | - if ( !isset( $params['body']['_source']) ) { |
|
| 468 | + if (!isset($params['body']['_source'])) { |
|
| 469 | 469 | $params['body']['_source'] = true; |
| 470 | 470 | } |
| 471 | 471 | |
| 472 | - if ( $this->scriptFields ) { |
|
| 472 | + if ($this->scriptFields) { |
|
| 473 | 473 | $params['body']['script_fields'] = $this->scriptFields; |
| 474 | 474 | } |
| 475 | 475 | |
@@ -393,8 +393,7 @@ discard block |
||
| 393 | 393 | foreach ($hit['fields'] as $field => $data) { |
| 394 | 394 | if ( count($data) == 1 ) { |
| 395 | 395 | $row[$field] = array_shift($data); |
| 396 | - } |
|
| 397 | - else { |
|
| 396 | + } else { |
|
| 398 | 397 | $row[$field] = $data; |
| 399 | 398 | } |
| 400 | 399 | } |
@@ -416,8 +415,7 @@ discard block |
||
| 416 | 415 | $results = $this->fetchAll(); |
| 417 | 416 | if ( count($results) ) { |
| 418 | 417 | return array_shift($results); |
| 419 | - } |
|
| 420 | - else { |
|
| 418 | + } else { |
|
| 421 | 419 | return null; |
| 422 | 420 | } |
| 423 | 421 | } |