Skip to content

Commit

Permalink
Made necessary adjustments to make codebase compatible with PHP 8.2. …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
Radiergummi committed Aug 22, 2023
1 parent 4488303 commit 67bd4a7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
/**
* Collection
*
* @template T of Model
* @template-covariant T of Model
* @extends BaseCollection<array-key, T>
* @psalm-suppress TooManyTemplateParams
* @package Matchory\Elasticsearch
* @package Matchory\Elasticsearch
*/
class Collection extends BaseCollection
{
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/ExecutesQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use const PHP_SAPI;

/**
* @template T of Model
* @template-covariant T of Model
*/
trait ExecutesQueries
{
Expand Down
23 changes: 11 additions & 12 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,19 @@
use Matchory\Elasticsearch\Concerns\ExplainsQueries;
use Matchory\Elasticsearch\Concerns\ManagesIndices;
use Matchory\Elasticsearch\Interfaces\ConnectionInterface;

use function count;
use function json_encode;

use const JSON_THROW_ON_ERROR;

/**
* Query
* =====
* Query builder instance for Elasticsearch queries
*
* @package Matchory\Elasticsearch\Query
* @template T of Model
* @todo Rename to "Builder" for coherency with Eloquent. To avoid breaking
* changes, an alias should be registered for Query
* @package Matchory\Elasticsearch\Query
* @template-covariant T of Model
* @todo Rename to "Builder" for coherency with Eloquent. To avoid breaking
* changes, an alias should be registered for Query
*/
class Query implements Arrayable, JsonSerializable, Jsonable, IteratorAggregate
{
Expand Down Expand Up @@ -185,12 +183,13 @@ class Query implements Arrayable, JsonSerializable, Jsonable, IteratorAggregate
*
* @param ConnectionInterface $connection Elasticsearch Connection the query
* builder uses.
* @param T|null $model Model instance the query builder
* @param T|null $model Model instance the query builder
*/
public function __construct(
ConnectionInterface $connection,
Model|null $model = null
) {
Model|null $model = null
)
{
$this->connection = $connection;

/**
Expand Down Expand Up @@ -249,7 +248,7 @@ public function getModel(): Model
*
* @template TModel of Model
*
* @param Model $model Model to use for the current query.
* @param Model $model Model to use for the current query.
*
* @psalm-param TModel $model
*
Expand All @@ -264,8 +263,8 @@ public function setModel(Model $model): self
* Forwards calls to the model instance. If the called method is a scope,
* it will be applied to the query.
*
* @param string $method Name of the called method.
* @param array $parameters Parameters passed to the method.
* @param string $method Name of the called method.
* @param array $parameters Parameters passed to the method.
*
* @return $this Query builder instance.
* @throws BadMethodCallException
Expand Down

0 comments on commit 67bd4a7

Please sign in to comment.