From 62a00e71e39d242b608bef2e779dae5c156df9d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simonas=20=C5=A0erlinskas?= <simonas.serlinskas@nfq.com> Date: Wed, 5 Aug 2015 12:17:13 +0200 Subject: [PATCH] fixed code style issues --- src/Aggregation/TopHitsAggregation.php | 6 +++--- src/BuilderBag.php | 7 ++++--- src/Highlight/Highlight.php | 4 ++-- src/NameAwareTrait.php | 3 +++ src/Query/BoolQuery.php | 14 +++++++++++--- src/SearchEndpoint/AbstractSearchEndpoint.php | 3 ++- src/SearchEndpoint/AggregationsEndpoint.php | 2 +- src/SearchEndpoint/FilterEndpoint.php | 2 +- src/SearchEndpoint/HighlightEndpoint.php | 2 +- src/SearchEndpoint/PostFilterEndpoint.php | 2 +- src/SearchEndpoint/QueryEndpoint.php | 2 +- src/SearchEndpoint/SearchEndpointInterface.php | 12 ++++++------ src/SearchEndpoint/SortEndpoint.php | 4 ++-- src/Sort/FieldSort.php | 15 ++++++++------- tests/BuilderBagTest.php | 1 - tests/SearchEndpoint/AggregationsEndpointTest.php | 3 +++ tests/SearchEndpoint/FilterEndpointTest.php | 3 +++ tests/SearchEndpoint/HighlightEndpointTest.php | 3 +++ tests/SearchEndpoint/PostFilterEndpointTest.php | 3 +++ tests/SearchEndpoint/QueryEndpointTest.php | 3 +++ tests/SearchEndpoint/SortEndpointTest.php | 3 +++ 21 files changed, 64 insertions(+), 33 deletions(-) diff --git a/src/Aggregation/TopHitsAggregation.php b/src/Aggregation/TopHitsAggregation.php index d41e3d8..3ee3098 100644 --- a/src/Aggregation/TopHitsAggregation.php +++ b/src/Aggregation/TopHitsAggregation.php @@ -39,9 +39,9 @@ class TopHitsAggregation extends AbstractAggregation /** * Constructor for top hits. * - * @param string $name Aggregation name. - * @param null|int $size Number of top matching hits to return per bucket. - * @param null|int $from The offset from the first result you want to fetch. + * @param string $name Aggregation name. + * @param null|int $size Number of top matching hits to return per bucket. + * @param null|int $from The offset from the first result you want to fetch. * @param null|BuilderInterface $sort How the top matching hits should be sorted. */ public function __construct($name, $size = null, $from = null, $sort = null) diff --git a/src/BuilderBag.php b/src/BuilderBag.php index 4894764..439febc 100644 --- a/src/BuilderBag.php +++ b/src/BuilderBag.php @@ -66,7 +66,7 @@ class BuilderBag /** * Removes a builder by name. * - * @param string $name builder name. + * @param string $name Builder name. */ public function remove($name) { @@ -84,7 +84,7 @@ class BuilderBag /** * Returns a builder by name. * - * @param string $name builder name. + * @param string $name Builder name. * * @return BuilderInterface */ @@ -96,7 +96,7 @@ class BuilderBag /** * Returns all builders contained. * - * @param string|null $type builder type. + * @param string|null $type Builder type. * * @return BuilderInterface[] */ @@ -120,6 +120,7 @@ class BuilderBag foreach ($this->all() as $builder) { $output = array_merge($output, $builder->toArray()); } + return $output; } } diff --git a/src/Highlight/Highlight.php b/src/Highlight/Highlight.php index 7723ea0..171e6a1 100644 --- a/src/Highlight/Highlight.php +++ b/src/Highlight/Highlight.php @@ -32,8 +32,8 @@ class Highlight implements BuilderInterface private $tags; /** - * @param $name - * @param array $params + * @param string $name Field name to highlight. + * @param array $params * * @return $this */ diff --git a/src/NameAwareTrait.php b/src/NameAwareTrait.php index ddf7d90..c76c937 100644 --- a/src/NameAwareTrait.php +++ b/src/NameAwareTrait.php @@ -13,6 +13,9 @@ namespace ONGR\ElasticsearchDSL; trait NameAwareTrait { + /** + * @var string + */ private $name; /** diff --git a/src/Query/BoolQuery.php b/src/Query/BoolQuery.php index 0c4ed3b..3faed61 100644 --- a/src/Query/BoolQuery.php +++ b/src/Query/BoolQuery.php @@ -32,6 +32,9 @@ class BoolQuery implements BuilderInterface */ private $container = []; + /** + * Constructor to prepare container. + */ public function __construct() { $this->container = [ @@ -53,6 +56,10 @@ class BoolQuery implements BuilderInterface && count($this->container[self::MUST]) == 1; } + /** + * @param null $boolType + * @return array + */ public function getQueries($boolType = null) { if ($boolType === null) { @@ -69,9 +76,9 @@ class BoolQuery implements BuilderInterface /** * Add BuilderInterface object to bool operator. * - * @param BuilderInterface $query Query add to the bool. - * @param string $type Bool type. Example: must, must_not, should. - * @param string $key Key that indicates a builder id. + * @param BuilderInterface $query Query add to the bool. + * @param string $type Bool type. Example: must, must_not, should. + * @param string $key Key that indicates a builder id. * * @return string Key of added builder. * @@ -103,6 +110,7 @@ class BoolQuery implements BuilderInterface /** @var BuilderInterface $query */ $mustContainer = $this->container[self::MUST]; $query = array_shift($mustContainer); + return [$query->getType() => $query->toArray()]; } diff --git a/src/SearchEndpoint/AbstractSearchEndpoint.php b/src/SearchEndpoint/AbstractSearchEndpoint.php index d6bdc96..0ec3582 100644 --- a/src/SearchEndpoint/AbstractSearchEndpoint.php +++ b/src/SearchEndpoint/AbstractSearchEndpoint.php @@ -68,7 +68,8 @@ abstract class AbstractSearchEndpoint extends AbstractNormalizable implements Se /** * Checks if builder with specific key exists. * - * @param $key + * @param string $key Key to check if it exists in container. + * * @return bool */ public function has($key) diff --git a/src/SearchEndpoint/AggregationsEndpoint.php b/src/SearchEndpoint/AggregationsEndpoint.php index 444066d..56c2c50 100644 --- a/src/SearchEndpoint/AggregationsEndpoint.php +++ b/src/SearchEndpoint/AggregationsEndpoint.php @@ -22,7 +22,7 @@ class AggregationsEndpoint extends AbstractSearchEndpoint /** * Endpoint name */ - CONST NAME = 'aggregations'; + const NAME = 'aggregations'; /** * {@inheritdoc} diff --git a/src/SearchEndpoint/FilterEndpoint.php b/src/SearchEndpoint/FilterEndpoint.php index ef53e00..888ca1c 100644 --- a/src/SearchEndpoint/FilterEndpoint.php +++ b/src/SearchEndpoint/FilterEndpoint.php @@ -23,7 +23,7 @@ class FilterEndpoint extends QueryEndpoint /** * Endpoint name */ - CONST NAME = 'filter'; + const NAME = 'filter'; /** * {@inheritdoc} diff --git a/src/SearchEndpoint/HighlightEndpoint.php b/src/SearchEndpoint/HighlightEndpoint.php index ba4ff9c..45d9c9f 100644 --- a/src/SearchEndpoint/HighlightEndpoint.php +++ b/src/SearchEndpoint/HighlightEndpoint.php @@ -22,7 +22,7 @@ class HighlightEndpoint extends AbstractSearchEndpoint /** * Endpoint name */ - CONST NAME = 'highlight'; + const NAME = 'highlight'; /** * @var BuilderInterface diff --git a/src/SearchEndpoint/PostFilterEndpoint.php b/src/SearchEndpoint/PostFilterEndpoint.php index 88bfc57..27d67bd 100644 --- a/src/SearchEndpoint/PostFilterEndpoint.php +++ b/src/SearchEndpoint/PostFilterEndpoint.php @@ -22,7 +22,7 @@ class PostFilterEndpoint extends FilterEndpoint /** * Endpoint name */ - CONST NAME = 'post_filter'; + const NAME = 'post_filter'; /** * {@inheritdoc} diff --git a/src/SearchEndpoint/QueryEndpoint.php b/src/SearchEndpoint/QueryEndpoint.php index 89f5ec9..52f5059 100644 --- a/src/SearchEndpoint/QueryEndpoint.php +++ b/src/SearchEndpoint/QueryEndpoint.php @@ -28,7 +28,7 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI /** * Endpoint name */ - CONST NAME = 'query'; + const NAME = 'query'; /** * @var BoolQuery diff --git a/src/SearchEndpoint/SearchEndpointInterface.php b/src/SearchEndpoint/SearchEndpointInterface.php index 1399112..7ee7178 100644 --- a/src/SearchEndpoint/SearchEndpointInterface.php +++ b/src/SearchEndpoint/SearchEndpointInterface.php @@ -23,8 +23,8 @@ interface SearchEndpointInterface extends NormalizableInterface /** * Adds builder to search endpoint. * - * @param BuilderInterface $builder Builder to add. - * @param array $key Additional parameters relevant to builder. + * @param BuilderInterface $builder Builder to add. + * @param array $key Additional parameters relevant to builder. * * @return string Key of added builder. */ @@ -33,10 +33,10 @@ interface SearchEndpointInterface extends NormalizableInterface /** * Adds builder to search endpoint's specific bool type container. * - * @param BuilderInterface $builder Builder to add. - * @param array $boolType Bool type for query or filter. If bool type is left null - * it will be treated as MUST. - * @param array $key Additional parameters relevant to builder. + * @param BuilderInterface $builder Builder to add. + * @param array $boolType Bool type for query or filter. If bool type is left null + * it will be treated as MUST. + * @param array $key Additional parameters relevant to builder. * * @return string Key of added builder. */ diff --git a/src/SearchEndpoint/SortEndpoint.php b/src/SearchEndpoint/SortEndpoint.php index 13eaf6a..d19249d 100644 --- a/src/SearchEndpoint/SortEndpoint.php +++ b/src/SearchEndpoint/SortEndpoint.php @@ -24,7 +24,7 @@ class SortEndpoint extends AbstractSearchEndpoint /** * Endpoint name */ - CONST NAME = 'sort'; + const NAME = 'sort'; /** * {@inheritdoc} @@ -33,7 +33,7 @@ class SortEndpoint extends AbstractSearchEndpoint { $output = []; - foreach($this->getAll() as $sort) { + foreach ($this->getAll() as $sort) { $output[] = $sort->toArray(); } diff --git a/src/Sort/FieldSort.php b/src/Sort/FieldSort.php index 394affc..c9ae2d6 100644 --- a/src/Sort/FieldSort.php +++ b/src/Sort/FieldSort.php @@ -18,8 +18,8 @@ use ONGR\ElasticsearchDSL\BuilderInterface; */ class FieldSort implements BuilderInterface { - CONST ASC = 'asc'; - CONST DESC = 'desc'; + const ASC = 'asc'; + const DESC = 'desc'; /** * @var string. @@ -37,8 +37,8 @@ class FieldSort implements BuilderInterface private $nestedFilter; /** - * @param string $field Field name. - * @param array $params Params that can be set to field sort. + * @param string $field Field name. + * @param array $params Params that can be set to field sort. */ public function __construct($field, $params = []) { @@ -80,9 +80,10 @@ class FieldSort implements BuilderInterface if ($this->nestedFilter) { $fieldValues = array_merge( $this->params, - ['nested_filter' => [ - $this->nestedFilter->getType() => $this->nestedFilter->toArray(), - ] + [ + 'nested_filter' => [ + $this->nestedFilter->getType() => $this->nestedFilter->toArray(), + ], ] ); } else { diff --git a/tests/BuilderBagTest.php b/tests/BuilderBagTest.php index b2f7a95..ec16fc0 100644 --- a/tests/BuilderBagTest.php +++ b/tests/BuilderBagTest.php @@ -32,7 +32,6 @@ class BuilderBagTest extends \PHPUnit_Framework_TestCase */ public function testRemove() { - $bag = new BuilderBag(); $fooBuilder = $this->getBuilder('foo'); $acmeBuilder = $this->getBuilder('acme'); diff --git a/tests/SearchEndpoint/AggregationsEndpointTest.php b/tests/SearchEndpoint/AggregationsEndpointTest.php index 510421b..8a618dd 100644 --- a/tests/SearchEndpoint/AggregationsEndpointTest.php +++ b/tests/SearchEndpoint/AggregationsEndpointTest.php @@ -30,6 +30,9 @@ class AggregationsEndpointTest extends \PHPUnit_Framework_TestCase ); } + /** + * Tests if endpoint returns builders. + */ public function testEndpointGetter() { $aggName = 'acme_agg'; diff --git a/tests/SearchEndpoint/FilterEndpointTest.php b/tests/SearchEndpoint/FilterEndpointTest.php index 69d2921..814fbd1 100644 --- a/tests/SearchEndpoint/FilterEndpointTest.php +++ b/tests/SearchEndpoint/FilterEndpointTest.php @@ -67,6 +67,9 @@ class FilterEndpointTest extends \PHPUnit_Framework_TestCase $this->assertSame($matchAllFilter, $reference->getFilter()); } + /** + * Tests if endpoint returns builders. + */ public function testEndpointGetter() { $filterName = 'acme_filter'; diff --git a/tests/SearchEndpoint/HighlightEndpointTest.php b/tests/SearchEndpoint/HighlightEndpointTest.php index 85200ae..ff5e44f 100644 --- a/tests/SearchEndpoint/HighlightEndpointTest.php +++ b/tests/SearchEndpoint/HighlightEndpointTest.php @@ -52,6 +52,9 @@ class HighlightEndpointTest extends \PHPUnit_Framework_TestCase ); } + /** + * Tests if endpoint returns builders. + */ public function testEndpointGetter() { $highlightName = 'acme_highlight'; diff --git a/tests/SearchEndpoint/PostFilterEndpointTest.php b/tests/SearchEndpoint/PostFilterEndpointTest.php index 3490ba7..75236a1 100644 --- a/tests/SearchEndpoint/PostFilterEndpointTest.php +++ b/tests/SearchEndpoint/PostFilterEndpointTest.php @@ -59,6 +59,9 @@ class PostFilterEndpointTest extends \PHPUnit_Framework_TestCase ); } + /** + * Tests if endpoint returns builders. + */ public function testEndpointGetter() { $filterName = 'acme_post_filter'; diff --git a/tests/SearchEndpoint/QueryEndpointTest.php b/tests/SearchEndpoint/QueryEndpointTest.php index 0a17c70..71dfd09 100644 --- a/tests/SearchEndpoint/QueryEndpointTest.php +++ b/tests/SearchEndpoint/QueryEndpointTest.php @@ -60,6 +60,9 @@ class QueryEndpointTest extends \PHPUnit_Framework_TestCase ); } + /** + * Tests if endpoint returns builders. + */ public function testEndpointGetter() { $queryName = 'acme_query'; diff --git a/tests/SearchEndpoint/SortEndpointTest.php b/tests/SearchEndpoint/SortEndpointTest.php index c347583..5f21c9d 100644 --- a/tests/SearchEndpoint/SortEndpointTest.php +++ b/tests/SearchEndpoint/SortEndpointTest.php @@ -50,6 +50,9 @@ class SortEndpointTest extends \PHPUnit_Framework_TestCase ); } + /** + * Tests if endpoint returns builders. + */ public function testEndpointGetter() { $sortName = 'acme_sort'; -- GitLab