From 33f1bd00de46bf4ecd89fa1da8eb871ba447df5f Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Wed, 28 Aug 2024 10:36:09 +0200 Subject: [PATCH] Increase PHPStan level --- composer.json | 1 + phpstan.neon.dist | 4 +++- src/Relations/BelongsToThrough.php | 3 ++- tests/Models/Comment.php | 13 +++++++------ 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/composer.json b/composer.json index 41283b2..d1f2eea 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ }, "require-dev": { "barryvdh/laravel-ide-helper": "^3.0", + "larastan/larastan": "^2.9", "orchestra/testbench": "^9.0", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^11.0" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 47e3df0..cd2b068 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,7 @@ +includes: + - ./vendor/larastan/larastan/extension.neon parameters: - level: 0 + level: 1 paths: - src - tests diff --git a/src/Relations/BelongsToThrough.php b/src/Relations/BelongsToThrough.php index a37ac5d..0029cc5 100644 --- a/src/Relations/BelongsToThrough.php +++ b/src/Relations/BelongsToThrough.php @@ -59,8 +59,9 @@ class BelongsToThrough extends Relation * @param string $prefix * @param array $foreignKeyLookup * @param array $localKeyLookup - * * @return void + * + * @phpstan-ignore constructor.unusedParameter($localKey) */ public function __construct( Builder $query, diff --git a/tests/Models/Comment.php b/tests/Models/Comment.php index 0b994fc..25f2e51 100644 --- a/tests/Models/Comment.php +++ b/tests/Models/Comment.php @@ -2,18 +2,19 @@ namespace Tests\Models; +use Znck\Eloquent\Relations\BelongsToThrough; use Znck\Eloquent\Traits\HasTableAlias; class Comment extends Model { use HasTableAlias; - public function country() + public function country(): BelongsToThrough { return $this->belongsToThrough(Country::class, [User::class, Post::class])->withDefault(); } - public function countryWithCustomForeignKeys() + public function countryWithCustomForeignKeys(): BelongsToThrough { return $this->belongsToThrough( Country::class, @@ -24,22 +25,22 @@ public function countryWithCustomForeignKeys() ); } - public function countryWithTrashedUser() + public function countryWithTrashedUser(): BelongsToThrough { return $this->country()->withTrashed(['users.deleted_at']); } - public function countryWithPrefix() + public function countryWithPrefix(): BelongsToThrough { return $this->belongsToThrough(Country::class, [User::class, Post::class], null, 'custom_'); } - public function grandparent() + public function grandparent(): BelongsToThrough { return $this->belongsToThrough(self::class, self::class.' as alias', null, '', [self::class => 'parent_id']); } - public function user() + public function user(): BelongsToThrough { return $this->belongsToThrough(User::class, Post::class); }