Skip to content

Commit 67bd4a7

Browse files
committed
Made necessary adjustments to make codebase compatible with PHP 8.2. This involved switching to covariant templates for Models on Collection.php, ExecutesQueries.php and Query.php. Removed unnecessary lines in Query.php to improve readability. Also fixed some minor alignment issues in Query.php to maintain consistency. Changes will enhance static type handling and readability.
1 parent 4488303 commit 67bd4a7

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/Collection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
/**
1717
* Collection
1818
*
19-
* @template T of Model
19+
* @template-covariant T of Model
2020
* @extends BaseCollection<array-key, T>
2121
* @psalm-suppress TooManyTemplateParams
22-
* @package Matchory\Elasticsearch
22+
* @package Matchory\Elasticsearch
2323
*/
2424
class Collection extends BaseCollection
2525
{

src/Concerns/ExecutesQueries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use const PHP_SAPI;
3030

3131
/**
32-
* @template T of Model
32+
* @template-covariant T of Model
3333
*/
3434
trait ExecutesQueries
3535
{

src/Query.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,19 @@
2020
use Matchory\Elasticsearch\Concerns\ExplainsQueries;
2121
use Matchory\Elasticsearch\Concerns\ManagesIndices;
2222
use Matchory\Elasticsearch\Interfaces\ConnectionInterface;
23-
2423
use function count;
2524
use function json_encode;
26-
2725
use const JSON_THROW_ON_ERROR;
2826

2927
/**
3028
* Query
3129
* =====
3230
* Query builder instance for Elasticsearch queries
3331
*
34-
* @package Matchory\Elasticsearch\Query
35-
* @template T of Model
36-
* @todo Rename to "Builder" for coherency with Eloquent. To avoid breaking
37-
* changes, an alias should be registered for Query
32+
* @package Matchory\Elasticsearch\Query
33+
* @template-covariant T of Model
34+
* @todo Rename to "Builder" for coherency with Eloquent. To avoid breaking
35+
* changes, an alias should be registered for Query
3836
*/
3937
class Query implements Arrayable, JsonSerializable, Jsonable, IteratorAggregate
4038
{
@@ -185,12 +183,13 @@ class Query implements Arrayable, JsonSerializable, Jsonable, IteratorAggregate
185183
*
186184
* @param ConnectionInterface $connection Elasticsearch Connection the query
187185
* builder uses.
188-
* @param T|null $model Model instance the query builder
186+
* @param T|null $model Model instance the query builder
189187
*/
190188
public function __construct(
191189
ConnectionInterface $connection,
192-
Model|null $model = null
193-
) {
190+
Model|null $model = null
191+
)
192+
{
194193
$this->connection = $connection;
195194

196195
/**
@@ -249,7 +248,7 @@ public function getModel(): Model
249248
*
250249
* @template TModel of Model
251250
*
252-
* @param Model $model Model to use for the current query.
251+
* @param Model $model Model to use for the current query.
253252
*
254253
* @psalm-param TModel $model
255254
*
@@ -264,8 +263,8 @@ public function setModel(Model $model): self
264263
* Forwards calls to the model instance. If the called method is a scope,
265264
* it will be applied to the query.
266265
*
267-
* @param string $method Name of the called method.
268-
* @param array $parameters Parameters passed to the method.
266+
* @param string $method Name of the called method.
267+
* @param array $parameters Parameters passed to the method.
269268
*
270269
* @return $this Query builder instance.
271270
* @throws BadMethodCallException

0 commit comments

Comments
 (0)