Skip to content

Commit

Permalink
style(core): fixs
Browse files Browse the repository at this point in the history
  • Loading branch information
Guikingone committed Nov 24, 2020
1 parent bacd343 commit 9f8e368
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Endpoints/Indexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function search($query, array $searchParams = [], array $options = []): S

$searchResult = new SearchResult($result);

if (array_key_exists('filteringHits', $options) && is_callable($options['filteringHits'])) {
if (\array_key_exists('filteringHits', $options) && \is_callable($options['filteringHits'])) {
$searchResult = $searchResult->filter($options['filteringHits']);
}

Expand Down
14 changes: 6 additions & 8 deletions src/Search/SearchResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace MeiliSearch\Search;

use function array_filter;
use ArrayIterator;
use function count;
use Countable;
use IteratorAggregate;
use function array_filter;
use function count;

class SearchResult implements Countable, IteratorAggregate
{
Expand Down Expand Up @@ -77,16 +77,14 @@ public function __construct(array $body)
*
* The method DOES not trigger a new search.
*
* @param callable $callback
*
* @return SearchResult
*/
public function filter(callable $callback): self
{
$results = array_filter($this->hits, $callback, ARRAY_FILTER_USE_BOTH);

$this->hits = $results;
$this->nbHits = count($results);
$this->nbHits = \count($results);

return $this;
}
Expand Down Expand Up @@ -121,7 +119,7 @@ public function getMatches(): int

public function getNbHits(): int
{
return count($this->hits);
return \count($this->hits);
}

public function getExhaustiveNbHits(): bool
Expand Down Expand Up @@ -159,7 +157,7 @@ public function toArray(): array
'offset' => $this->offset,
'limit' => $this->limit,
'matches' => $this->nbHits,
'nbHits' => count($this->hits),
'nbHits' => \count($this->hits),
'exhaustiveNbHits' => $this->exhaustiveNbHits,
'processingTimeMs' => $this->processingTimeMs,
'query' => $this->query,
Expand All @@ -175,6 +173,6 @@ public function getIterator(): ArrayIterator

public function count(): int
{
return count($this->hits);
return \count($this->hits);
}
}
2 changes: 1 addition & 1 deletion tests/Search/SearchResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function testSearchResultCanBeFiltered(): void
]);

$filteredResults = $result->filter(function (array $hit, int $_): bool {
return strtoupper($hit['title']) === 'AMERICAN SNIPER';
return 'AMERICAN SNIPER' === strtoupper($hit['title']);
});

static::assertSame(1, $filteredResults->count());
Expand Down

0 comments on commit 9f8e368

Please sign in to comment.