Skip to content
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

Fix Laravel 9 PHPStan generic check for __invoke() method of Filter #781

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use Illuminate\Database\Eloquent\Builder;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
*/
interface Filter
{
/**
* @param \Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $query
* @param \Illuminate\Database\Eloquent\Builder<TModelClass> $query
* @param mixed $value
* @param string $property
*
Expand Down
4 changes: 4 additions & 0 deletions src/Filters/FiltersCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Illuminate\Database\Eloquent\Builder;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @template-implements \Spatie\QueryBuilder\Filters\Filter<TModelClass>
*/
class FiltersCallback implements Filter
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Filters/FiltersExact.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @template-implements \Spatie\QueryBuilder\Filters\Filter<TModelClass>
*/
class FiltersExact implements Filter
{
protected $relationConstraints = [];
Expand All @@ -19,6 +23,7 @@ public function __construct(bool $addRelationConstraint = true)
$this->addRelationConstraint = $addRelationConstraint;
}

/** {@inheritdoc} */
public function __invoke(Builder $query, $value, string $property)
{
if ($this->addRelationConstraint) {
Expand Down
5 changes: 5 additions & 0 deletions src/Filters/FiltersPartial.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

use Illuminate\Database\Eloquent\Builder;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @template-implements \Spatie\QueryBuilder\Filters\Filter<TModelClass>
*/
class FiltersPartial extends FiltersExact implements Filter
{
/** {@inheritdoc} */
public function __invoke(Builder $query, $value, string $property)
{
if ($this->addRelationConstraint) {
Expand Down
5 changes: 5 additions & 0 deletions src/Filters/FiltersScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@
use ReflectionUnionType;
use Spatie\QueryBuilder\Exceptions\InvalidFilterValue;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @template-implements \Spatie\QueryBuilder\Filters\Filter<TModelClass>
*/
class FiltersScope implements Filter
{
/** {@inheritdoc} */
public function __invoke(Builder $query, $values, string $property): Builder
{
$propertyParts = collect(explode('.', $property));
Expand Down
4 changes: 4 additions & 0 deletions src/Filters/FiltersTrashed.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Illuminate\Database\Eloquent\Builder;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @template-implements \Spatie\QueryBuilder\Filters\Filter<TModelClass>
*/
class FiltersTrashed implements Filter
{
/** {@inheritdoc} */
Expand Down
5 changes: 5 additions & 0 deletions tests/TestClasses/Filters/FiltersTestModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
use Illuminate\Database\Eloquent\Builder;
use Spatie\QueryBuilder\Filters\Filter;

/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @template-implements \Spatie\QueryBuilder\Filters\Filter<TModelClass>
*/
class FiltersTestModels implements Filter
{
/** {@inheritdoc} */
public function __invoke(Builder $query, $value, string $property): Builder
{
return $query->where($property, $value);
Expand Down