From 3fd521af29315b72077714af09a2e15a1ddf0b25 Mon Sep 17 00:00:00 2001 From: Andrei Ivchenkov Date: Thu, 12 Dec 2024 01:29:09 +0300 Subject: [PATCH 1/2] phpstan 2 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 21ca361a..4e249e83 100644 --- a/composer.json +++ b/composer.json @@ -44,11 +44,11 @@ "php-cs-fixer/shim": "^3.59.3", "guzzlehttp/guzzle": "^7.8.1", "http-interop/http-factory-guzzle": "^1.2.0", - "phpstan/phpstan": "^1.11.5", + "phpstan/phpstan": "^2.0", "phpstan/extension-installer": "^1.4.1", - "phpstan/phpstan-strict-rules": "^1.6.0", - "phpstan/phpstan-phpunit": "^1.4.0", - "phpstan/phpstan-deprecation-rules": "^1.2.0" + "phpstan/phpstan-strict-rules": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpstan/phpstan-deprecation-rules": "^2.0" }, "scripts": { "lint": [ From 368c73f182f21f6e8b346283229f221fdb1f042e Mon Sep 17 00:00:00 2001 From: Andrei Ivchenkov Date: Thu, 12 Dec 2024 01:33:06 +0300 Subject: [PATCH 2/2] fixed errors after phpstan update --- src/Http/Client.php | 4 ++-- src/Search/SearchResult.php | 24 ++++++++++++------------ tests/Endpoints/SearchTest.php | 19 ++++++++++++++++++- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/Http/Client.php b/src/Http/Client.php index afffc154..2d5486e5 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -47,9 +47,9 @@ public function __construct( $this->http = $httpClient ?? Psr18ClientDiscovery::find(); $this->requestFactory = $reqFactory ?? Psr17FactoryDiscovery::findRequestFactory(); $this->streamFactory = $streamFactory ?? Psr17FactoryDiscovery::findStreamFactory(); - $this->headers = array_filter([ + $this->headers = [ 'User-Agent' => implode(';', array_merge($clientAgents, [Meilisearch::qualifiedVersion()])), - ]); + ]; if (null !== $apiKey && '' !== $apiKey) { $this->headers['Authorization'] = \sprintf('Bearer %s', $apiKey); } diff --git a/src/Search/SearchResult.php b/src/Search/SearchResult.php index 225197a6..3873a72b 100644 --- a/src/Search/SearchResult.php +++ b/src/Search/SearchResult.php @@ -19,16 +19,16 @@ class SearchResult implements \Countable, \IteratorAggregate * and its value will not be modified by the methods in this class. * Please, use `hitsCount` if you want to know the real size of the `hits` array at any time. */ - private ?int $estimatedTotalHits; - private ?int $hitsCount; - private ?int $offset; - private ?int $limit; - private ?int $semanticHitCount; + private ?int $estimatedTotalHits = null; + private int $hitsCount; + private ?int $offset = null; + private ?int $limit = null; + private int $semanticHitCount; - private ?int $hitsPerPage; - private ?int $page; - private ?int $totalPages; - private ?int $totalHits; + private ?int $hitsPerPage = null; + private ?int $page = null; + private ?int $totalPages = null; + private ?int $totalHits = null; private int $processingTimeMs; private bool $numberedPagination; @@ -126,12 +126,12 @@ public function getHits(): array return $this->hits; } - public function getOffset(): int + public function getOffset(): ?int { return $this->offset; } - public function getLimit(): int + public function getLimit(): ?int { return $this->limit; } @@ -154,7 +154,7 @@ public function count(): int return $this->hitsCount; } - public function getEstimatedTotalHits(): int + public function getEstimatedTotalHits(): ?int { return $this->estimatedTotalHits; } diff --git a/tests/Endpoints/SearchTest.php b/tests/Endpoints/SearchTest.php index eea4046c..0ce5d5af 100644 --- a/tests/Endpoints/SearchTest.php +++ b/tests/Endpoints/SearchTest.php @@ -26,9 +26,17 @@ public function testBasicSearch(): void $response = $this->index->search('prince'); $this->assertEstimatedPagination($response->toArray()); - self::assertSame(2, $response->getEstimatedTotalHits()); self::assertCount(2, $response->getHits()); + self::assertSame(2, $response->getEstimatedTotalHits()); + self::assertSame(0, $response->getOffset()); + self::assertSame(20, $response->getLimit()); + + self::assertNull($response->getHitsPerPage()); + self::assertNull($response->getPage()); + self::assertNull($response->getTotalPages()); + self::assertNull($response->getTotalHits()); + $response = $this->index->search('prince', [], [ 'raw' => true, ]); @@ -44,6 +52,15 @@ public function testBasicSearchWithFinitePagination(): void $this->assertFinitePagination($response->toArray()); self::assertCount(2, $response->getHits()); + self::assertSame(2, $response->getHitsPerPage()); + self::assertSame(1, $response->getPage()); + self::assertSame(1, $response->getTotalPages()); + self::assertSame(2, $response->getTotalHits()); + + self::assertNull($response->getEstimatedTotalHits()); + self::assertNull($response->getOffset()); + self::assertNull($response->getLimit()); + $response = $this->index->search('prince', ['hitsPerPage' => 2], [ 'raw' => true, ]);