Skip to content

Bump to PHP 8.1, improve type safety for Tasks #735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 41 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5815de8
Bump PHP requirement to 8.1
norkunas Apr 9, 2025
338f83d
Add missing types
norkunas Apr 9, 2025
c6d4147
Add task object and related enums
norkunas Apr 9, 2025
ed7b13a
Replace task array return with Task object
norkunas Apr 9, 2025
7087a12
Add tests for missing coverage report
norkunas Apr 10, 2025
f6d5c9e
Fix conflicts
norkunas May 5, 2025
3bb0a8b
Remove unused variable
norkunas May 14, 2025
ffa2ba5
Fix test method name
norkunas May 14, 2025
81513fe
Add a missing phpdoc type for documentId validation
norkunas May 14, 2025
8d1c30c
Remove task type that does not exist
norkunas May 14, 2025
612f58a
Add comment about array access retrocompatibility
norkunas May 14, 2025
f6f05dd
Fix tests after `TaskType::documentEdition` removal
norkunas May 14, 2025
546bc7e
Revert "Fix tests after `TaskType::documentEdition` removal"
norkunas May 14, 2025
63eaa6a
Revert "Remove task type that does not exist"
norkunas May 14, 2025
cbd0c25
Add a `non-negative-int` hint for `searchCutoffMs` setting value
norkunas May 14, 2025
d4d7e24
Add typed TaskDetails and TaskError + fix namespace casing
norkunas May 14, 2025
f424477
Wrap in Task `Indexes::getTask`
norkunas May 14, 2025
7b53b52
Rename `$promise` to `$task` in tests
norkunas May 14, 2025
5c7a8ec
Wrap tasks in `TasksResults` object with `Task` object
norkunas May 14, 2025
8514102
Replace task array access usage with getters
norkunas May 14, 2025
8de831c
Completely replace array data usage
norkunas May 14, 2025
63fdbbe
Fix bot review
norkunas May 14, 2025
07ca854
Add assertion
norkunas May 14, 2025
dc8dc1d
Fix missing coverage
norkunas May 14, 2025
ee6a90f
Fix phpstan errors
norkunas May 14, 2025
90304c5
Configure phpunit to display deprecations/errors/notices/warnings
norkunas May 15, 2025
8b034a3
Fix TaskDeletionDetails to accept `deletedTasks`
norkunas May 15, 2025
d708780
Fix `DocumentDeletionDetails` to not require `providedIds` (not avail…
norkunas May 15, 2025
e2cc923
Remove task array access
norkunas May 15, 2025
80b10ae
Fix test
norkunas May 15, 2025
7571178
Add missing typehints
norkunas May 16, 2025
b23790a
Add the `disableOnNumbers` field to SettingsUpdateDetails on `typoTol…
norkunas Jun 3, 2025
9a9349e
Fix code review
norkunas Jun 3, 2025
9cf7a37
Add `wait` method to task
norkunas Jun 3, 2025
0c986ea
Use `str_contains`
norkunas Jun 3, 2025
5b7c3e6
Fix another review comment
norkunas Jun 4, 2025
f888fd7
Avoid count
norkunas Jun 4, 2025
aabe2e1
Always use JSON_THROW_ON_ERROR
norkunas Jun 4, 2025
d43feca
Fix CS
norkunas Jun 4, 2025
3f0bffc
Fix lint
norkunas Jun 10, 2025
28c45ee
Fix test
norkunas Jun 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/meilisearch-beta-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ jobs:
MEILI_NO_ANALYTICS: true
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php-version: ['8.1', '8.2', '8.3', '8.4']
http-client: ['Guzzle-7', 'Guzzle-7-Adapter', 'Symfony-HttpClient', 'PHP-HTTP-CurlClient', 'Kriswallsmith-Buzz']
exclude:
- php-version: '7.4'
http-client: 'Symfony-HttpClient'
- php-version: '8.0'
http-client: 'Symfony-HttpClient'
- php-version: '8.1'
http-client: 'Symfony-HttpClient'

Expand Down
42 changes: 1 addition & 41 deletions .github/workflows/pre-release-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ jobs:
MEILI_NO_ANALYTICS: true
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php-version: ['8.1', '8.2', '8.3', '8.4']
http-client: ['Guzzle-7', 'Guzzle-7-Adapter', 'Symfony-HttpClient', 'PHP-HTTP-CurlClient', 'Kriswallsmith-Buzz']
exclude:
- php-version: '7.4'
http-client: 'Symfony-HttpClient'
- php-version: '8.0'
http-client: 'Symfony-HttpClient'
- php-version: '8.1'
http-client: 'Symfony-HttpClient'
steps:
Expand Down Expand Up @@ -88,39 +84,3 @@ jobs:

- name: Run test suite
run: sh scripts/tests.sh

test_php_7_guzzle_6:
runs-on: ubuntu-latest
needs: ['meilisearch-version']
name: integration-tests-against-rc (PHP 7.4 & Guzzle 6)
services:
meilisearch:
image: getmeili/meilisearch:${{ needs.meilisearch-version.outputs.version }}
env:
MEILI_MASTER_KEY: 'masterKey'
MEILI_NO_ANALYTICS: 'true'
ports:
- '7700:7700'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate

- name: Switch to Guzzle 6
run: |
sed -i 's/"guzzlehttp\/guzzle": "^[0-9]\+\.[0-9]\+\.[0-9]\+\",/"php-http\/guzzle6-adapter": "^2.0.2",/' composer.json

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: Run test suite - php-http/guzzle6-adapter
run: sh scripts/tests.sh
44 changes: 1 addition & 43 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,9 @@ jobs:
MEILI_NO_ANALYTICS: true
strategy:
matrix:
php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php-version: ['8.1', '8.2', '8.3', '8.4']
http-client: ['Guzzle-7', 'Guzzle-7-Adapter', 'Symfony-HttpClient', 'PHP-HTTP-CurlClient', 'Kriswallsmith-Buzz']
exclude:
- php-version: '7.4'
http-client: 'Symfony-HttpClient'
- php-version: '8.0'
http-client: 'Symfony-HttpClient'
- php-version: '8.1'
http-client: 'Symfony-HttpClient'

Expand Down Expand Up @@ -136,44 +132,6 @@ jobs:
name: 'phpunit-${{ matrix.php-version }}-${{ matrix.http-client }}-coverage'
path: 'coverage*.xml'

test_php_7_guzzle_6:
# Will not run if the event is a PR to bump-meilisearch-v* (so a pre-release PR)
# Will still run for each push to bump-meilisearch-v*
if: github.event_name != 'pull_request' || !startsWith(github.base_ref, 'bump-meilisearch-v')
runs-on: ubuntu-latest
services:
meilisearch:
image: getmeili/meilisearch:latest
ports:
- 7700:7700
env:
MEILI_MASTER_KEY: masterKey
MEILI_NO_ANALYTICS: true

name: integration-tests (PHP 7.4 & Guzzle 6)
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: none

- name: Validate composer.json and composer.lock
run: composer validate

- name: Switch to Guzzle 6
run: |
sed -i 's/"guzzlehttp\/guzzle": "^[0-9]\+\.[0-9]\+\.[0-9]\+\",/"php-http\/guzzle6-adapter": "^2.0.2",/' composer.json

- name: Install dependencies
uses: ramsey/composer-install@v3

- name: Run test suite - php-http/guzzle6-adapter
run: sh scripts/tests.sh

upload-coverage:
name: Upload coverage to Codecov
runs-on: ubuntu-latest
Expand Down
5 changes: 2 additions & 3 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
'void_return' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'php_unit_strict' => true,
// @todo: when we'll support only PHP 8.0 and upper, we can enable `parameters` for `trailing_comma_in_multiline` rule
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['array_destructuring', 'arrays', 'match'/* , 'parameters' */]],
'php_unit_strict' => false,
'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['array_destructuring', 'arrays', 'match', 'parameters']],
])
->setRiskyAllowed(true)
->setFinder($finder);
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@
],
"minimum-stability": "stable",
"require": {
"php": "^7.4 || ^8.0",
"php": "^8.1",
"ext-json": "*",
"php-http/discovery": "^1.7",
"php-http/discovery": "^1.19",
"psr/http-client": "^1.0"
},
"autoload": {
"psr-4": {
"MeiliSearch\\": "src/",
"Meilisearch\\": "src/"
}
},
"files": [
"src/functions.php"
]
},
"autoload-dev": {
"psr-4": {
Expand All @@ -40,7 +43,7 @@
"http-interop/http-factory-guzzle": "Factory for guzzlehttp/guzzle"
},
"require-dev": {
"phpunit/phpunit": "^9.5 || ^10.5",
"phpunit/phpunit": "^10.5",
"php-cs-fixer/shim": "^3.59.3",
"guzzlehttp/guzzle": "^7.8.1",
"http-interop/http-factory-guzzle": "^1.2.0",
Expand Down
25 changes: 23 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" stopOnFailure="false" cacheResult="false" colors="true" cacheDirectory=".phpunit.cache">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
stopOnFailure="false"
cacheResult="false"
colors="true"
cacheDirectory=".phpunit.cache"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">./tests</directory>
Expand All @@ -9,7 +22,15 @@
<env name="MEILISEARCH_URL" value="http://localhost:7700"/>
<env name="MEILISEARCH_API_KEY" value="masterKey"/>
</php>
<source>
<source
ignoreSuppressionOfDeprecations="true"
ignoreSuppressionOfPhpDeprecations="true"
ignoreSuppressionOfErrors="true"
ignoreSuppressionOfNotices="true"
ignoreSuppressionOfPhpNotices="true"
ignoreSuppressionOfWarnings="true"
ignoreSuppressionOfPhpWarnings="true"
>
<include>
<directory>src/</directory>
</include>
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(
?ClientInterface $httpClient = null,
?RequestFactoryInterface $requestFactory = null,
array $clientAgents = [],
?StreamFactoryInterface $streamFactory = null
?StreamFactoryInterface $streamFactory = null,
) {
$this->http = new MeilisearchClientAdapter($url, $apiKey, $httpClient, $requestFactory, $clientAgents, $streamFactory);
$this->index = new Indexes($this->http);
Expand Down
11 changes: 3 additions & 8 deletions src/Contracts/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Data implements \ArrayAccess, \Countable, \IteratorAggregate
{
protected $data = [];
protected array $data = [];

public function __construct(array $data = [])
{
Expand All @@ -28,14 +28,9 @@ public function offsetUnset($offset): void
unset($this->data[$offset]);
}

#[\ReturnTypeWillChange]
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
if (isset($this->data[$offset])) {
return $this->data[$offset];
}

return null;
return $this->data[$offset] ?? null;
}

public function count(): int
Expand Down
6 changes: 3 additions & 3 deletions src/Contracts/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public function get(string $path, array $query = []);
* @throws ApiException
* @throws \JsonException
*/
public function post(string $path, $body = null, array $query = [], ?string $contentType = null);
public function post(string $path, mixed $body = null, array $query = [], ?string $contentType = null);

/**
* @param non-empty-string|null $contentType
*
* @throws ApiException
* @throws \JsonException
*/
public function put(string $path, $body = null, array $query = [], ?string $contentType = null);
public function put(string $path, mixed $body = null, array $query = [], ?string $contentType = null);

/**
* @throws ApiException
* @throws \JsonException
*/
public function patch(string $path, $body = null, array $query = []);
public function patch(string $path, mixed $body = null, array $query = []);

/**
* @throws ApiException
Expand Down
21 changes: 8 additions & 13 deletions src/Contracts/SimilarDocumentsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
class SimilarDocumentsQuery
{
/**
* @var int|string
* @var int|non-empty-string
*/
private $id;
private int|string $id;

/**
* @var non-empty-string
Expand Down Expand Up @@ -42,16 +42,13 @@ class SimilarDocumentsQuery
*/
private ?array $filter = null;

/**
* @var int|float|null
*/
private $rankingScoreThreshold;
private int|float|null $rankingScoreThreshold = null;

/**
* @param int|string $id
* @param non-empty-string $embedder
* @param int|non-empty-string $id
* @param non-empty-string $embedder
*/
public function __construct($id, string $embedder)
public function __construct(int|string $id, string $embedder)
{
$this->id = $id;
$this->embedder = $embedder;
Expand Down Expand Up @@ -142,11 +139,9 @@ public function setRetrieveVectors(?bool $retrieveVectors): self
}

/**
* @param int|float|null $rankingScoreThreshold
*
* @return $this
*/
public function setRankingScoreThreshold($rankingScoreThreshold): self
public function setRankingScoreThreshold(int|float|null $rankingScoreThreshold): self
{
$this->rankingScoreThreshold = $rankingScoreThreshold;

Expand All @@ -155,7 +150,7 @@ public function setRankingScoreThreshold($rankingScoreThreshold): self

/**
* @return array{
* id: int|string,
* id: int|non-empty-string,
* embedder: non-empty-string,
* offset?: non-negative-int,
* limit?: positive-int,
Expand Down
Loading
Loading