Skip to content

Commit

Permalink
fix: update PHPStan version and stubs
Browse files Browse the repository at this point in the history
Fixes #926
  • Loading branch information
canvural committed Feb 28, 2022
1 parent 965a451 commit 57dbe5f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 32 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"illuminate/pipeline": "^9",
"illuminate/support": "^9",
"mockery/mockery": "^1.4.4",
"phpstan/phpstan": "^1.4.2"
"phpstan/phpstan": "^1.4.7"
},
"require-dev": {
"nikic/php-parser": "^4.13.2",
Expand Down
30 changes: 27 additions & 3 deletions stubs/EloquentBuilder.stub
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class Builder
/**
* Add a basic where clause to the query.
*
* @param \Closure|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column
* @param (\Closure(static<TModelClass>): void)|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
Expand All @@ -230,7 +230,7 @@ class Builder
/**
* Add an "or where" clause to the query.
*
* @param \Closure|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column
* @param (\Closure(static<TModelClass>): void)|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @return $this
Expand Down Expand Up @@ -392,7 +392,7 @@ class Builder
/**
* Add a basic where clause to the query, and return the first result.
*
* @param \Closure|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column
* @param (\Closure(static<TModelClass>): void)|model-property<TModelClass>|array<model-property<TModelClass>|int, mixed>|\Illuminate\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
Expand Down Expand Up @@ -443,6 +443,30 @@ class Builder
* @return mixed|$this
*/
public function unless($value, $callback, $default = null);

/**
* Paginate the given query.
*
* @param int|null $perPage
* @param array<array-key, mixed> $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Pagination\LengthAwarePaginator
*
* @throws \InvalidArgumentException
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null);

/**
* Paginate the given query into a simple paginator.
*
* @param int|null $perPage
* @param array<array-key, mixed> $columns
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null);
}

class Scope {}
Expand Down
4 changes: 2 additions & 2 deletions tests/Features/Methods/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ public function testOldestToBaseWithQueryExpression(): ?QueryBuilder
->toBase();
}

/** @phpstan-return Collection<int, User> */
public function testPluckToBaseWithQueryExpression(): ?Collection
/** @phpstan-return Collection<array-key, mixed> */
public function testPluckToBaseWithQueryExpression(): Collection
{
return User::query()
->whereNull('name')
Expand Down
26 changes: 0 additions & 26 deletions tests/Features/Methods/PaginatorExtension.php

This file was deleted.

2 changes: 2 additions & 0 deletions tests/Type/GeneralTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class GeneralTypeTest extends TypeInferenceTestCase
public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__.'/data/request-object.php');
yield from $this->gatherAssertTypes(__DIR__.'/data/eloquent-builder.php');
yield from $this->gatherAssertTypes(__DIR__.'/data/paginator-extension.php');
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Type/data/eloquent-builder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace EloquentBuilder;

use App\User;
use Illuminate\Database\Eloquent\Builder;
use function PHPStan\Testing\assertType;

User::query()->where(function (Builder $query) {
assertType('Illuminate\Database\Eloquent\Builder<App\User>', $query);
});
11 changes: 11 additions & 0 deletions tests/Type/data/paginator-extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace PaginatorExtension;

use App\User;
use function PHPStan\Testing\assertType;

assertType('array', User::paginate()->all());
assertType('array', User::simplePaginate()->all());

0 comments on commit 57dbe5f

Please sign in to comment.