Skip to content

Commit

Permalink
Increase PHPStan level
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Aug 29, 2024
1 parent d547f15 commit 4813f9b
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-mockery": "^1.1",
"phpunit/phpunit": "^11.0",
"staudenmeir/eloquent-json-relations": "^1.11",
"staudenmeir/laravel-adjacency-list": "^1.21"
Expand Down
5 changes: 4 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
includes:
- ./vendor/larastan/larastan/extension.neon
- ./vendor/phpstan/phpstan-mockery/extension.neon
parameters:
level: 1
level: 2
paths:
- src
- tests
ignoreErrors:
- '#Call to an undefined method .+::getQualifiedDeletedAtColumn\(\)#'
- '#Call to an undefined method .+::withTrashed\(\)#'
- '#Unsafe usage of new static\(\).#'
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public function withPivot(
?callable $postProcessor = null
) {
if ($columns === ['*']) {
$columns = $this->query->getConnection()->getSchemaBuilder()->getColumnListing($table);
/** @var \Illuminate\Database\Connection $connection */
$connection = $this->query->getConnection();

$columns = $connection->getSchemaBuilder()->getColumnListing($table);
}

$accessor = $accessor ?: $table;
Expand Down
1 change: 1 addition & 0 deletions src/HasManyDeep.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

/**
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
*
* @extends \Illuminate\Database\Eloquent\Relations\HasManyThrough<TRelatedModel>
*/
class HasManyDeep extends HasManyThrough implements ConcatenableRelation
Expand Down
3 changes: 2 additions & 1 deletion src/HasOneDeep.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

/**
* @template TRelatedModel of \Illuminate\Database\Eloquent\Model
* @extends \Illuminate\Database\Eloquent\Relations\HasOneThrough<TRelatedModel>
*
* @extends \Staudenmeir\EloquentHasManyDeep\HasManyDeep<TRelatedModel>
*/
class HasOneDeep extends HasManyDeep
{
Expand Down
3 changes: 3 additions & 0 deletions tests/Concatenation/EloquentJsonRelations/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use Staudenmeir\EloquentJsonRelations\JsonKey;

/**
* @property-read \Illuminate\Database\Eloquent\Relations\Pivot $pivot
*/
class Project extends Model
{
use HasRelationships;
Expand Down
3 changes: 3 additions & 0 deletions tests/Concatenation/EloquentJsonRelations/Models/Role.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Staudenmeir\EloquentHasManyDeep\HasRelationships;
use Staudenmeir\EloquentJsonRelations\JsonKey;

/**
* @property-read \Illuminate\Database\Eloquent\Relations\Pivot $pivot
*/
class Role extends Model
{
use HasRelationships;
Expand Down
4 changes: 4 additions & 0 deletions tests/Concatenation/LaravelAdjacencyList/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
use Staudenmeir\EloquentHasManyDeep\HasTableAlias;
use Staudenmeir\LaravelAdjacencyList\Eloquent\HasRecursiveRelationships;

/**
* @property-read \Tests\Concatenation\LaravelAdjacencyList\Models\Post $ancestorPost
* @property-read \Tests\Concatenation\LaravelAdjacencyList\Models\Post $descendantPost
*/
class User extends Model
{
use HasRelationships;
Expand Down
2 changes: 2 additions & 0 deletions tests/HasManyDeepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public function testExistenceQueryForThroughSelfRelationWithoutAliasTrait()

public function testWithTrashed()
{
/** @var \Tests\Models\User $user */
$user = Comment::find(33)->user()
->withTrashed()
->first();
Expand All @@ -181,6 +182,7 @@ public function testWithTrashedIntermediateAndWithCount()
{
$country = Country::withCount('commentsWithTrashedUsers as count')->first();

// @phpstan-ignore property.notFound
$this->assertEquals(3, $country->count);
}
}
6 changes: 6 additions & 0 deletions tests/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
use Staudenmeir\EloquentHasManyDeep\HasOneDeep;
use Staudenmeir\EloquentHasManyDeep\HasTableAlias;

/**
* @property-read \Tests\Models\Country|null $country
* @property-read \Tests\Models\Country|null $countryWithCustomThroughTable
* @property-read \Tests\Models\Post|null $post
* @property-read \Tests\Models\Post|null $rootPost
*/
class Comment extends Model
{
use HasTableAlias;
Expand Down
5 changes: 5 additions & 0 deletions tests/Models/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
use Staudenmeir\EloquentHasManyDeep\HasOneDeep;

/**
* @property-read \Tests\Models\Comment|null $comment
* @property-read \Tests\Models\Comment|null $commentFromRelations
* @property-read \Tests\Models\Comment|null $commentFromRelationsWithConstraints
*/
class Country extends Model
{
public function comment(): HasOneDeep
Expand Down
4 changes: 4 additions & 0 deletions tests/Models/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;

/**
* @property-read \Illuminate\Database\Eloquent\Relations\Pivot $pivot
* @property-read \Illuminate\Database\Eloquent\Relations\Pivot $role_user
*/
class Permission extends Model
{
use HasRelationships;
Expand Down
3 changes: 3 additions & 0 deletions tests/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Staudenmeir\EloquentHasManyDeep\HasManyDeep;

/**
* @property-read \Tests\Models\User|null $user
*/
class Post extends Model
{
public function comments(): HasMany
Expand Down

0 comments on commit 4813f9b

Please sign in to comment.