From 3d1cf594ea49bcd01265571f22eb6bdc70c064de Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Sun, 17 Nov 2024 15:06:19 +0100 Subject: [PATCH] Increase PHPStan level --- README.md | 2 +- phpstan.neon.dist | 2 +- phpstan.types.neon.dist | 2 +- .../Relations/Traits/IsCustomizable.php | 20 +++++++++++-------- .../Relations/Traits/JoinsThroughParents.php | 1 + src/HasManyDeep.php | 1 + 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 784aae5..6ed8a56 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![CI](https://github.com/staudenmeir/eloquent-has-many-deep/actions/workflows/ci.yml/badge.svg)](https://github.com/staudenmeir/eloquent-has-many-deep/actions/workflows/ci.yml?query=branch%3Amain) [![Code Coverage](https://codecov.io/gh/staudenmeir/eloquent-has-many-deep/graph/badge.svg?token=H59fIf4mG6)](https://codecov.io/gh/staudenmeir/eloquent-has-many-deep) -[![PHPStan](https://img.shields.io/badge/PHPStan-level%209-brightgreen.svg?style=flat)](https://github.com/staudenmeir/eloquent-has-many-deep/actions/workflows/static-analysis.yml?query=branch%3Amain) +[![PHPStan](https://img.shields.io/badge/PHPStan-level%2010-brightgreen.svg?style=flat)](https://github.com/staudenmeir/eloquent-has-many-deep/actions/workflows/static-analysis.yml?query=branch%3Amain) [![Latest Stable Version](https://poser.pugx.org/staudenmeir/eloquent-has-many-deep/v/stable)](https://packagist.org/packages/staudenmeir/eloquent-has-many-deep) [![Total Downloads](https://poser.pugx.org/staudenmeir/eloquent-has-many-deep/downloads)](https://packagist.org/packages/staudenmeir/eloquent-has-many-deep/stats) [![License](https://poser.pugx.org/staudenmeir/eloquent-has-many-deep/license)](https://github.com/staudenmeir/eloquent-has-many-deep/blob/main/LICENSE) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 6f458f1..4ea602c 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 9 + level: 10 paths: - src treatPhpDocTypesAsCertain: false diff --git a/phpstan.types.neon.dist b/phpstan.types.neon.dist index 188838b..8b809e8 100644 --- a/phpstan.types.neon.dist +++ b/phpstan.types.neon.dist @@ -1,6 +1,6 @@ includes: - ./vendor/larastan/larastan/extension.neon parameters: - level: 9 + level: 10 paths: - types diff --git a/src/Eloquent/Relations/Traits/IsCustomizable.php b/src/Eloquent/Relations/Traits/IsCustomizable.php index 4f3870a..3d56422 100644 --- a/src/Eloquent/Relations/Traits/IsCustomizable.php +++ b/src/Eloquent/Relations/Traits/IsCustomizable.php @@ -2,40 +2,44 @@ namespace Staudenmeir\EloquentHasManyDeep\Eloquent\Relations\Traits; +/** + * @template TRelatedModel of \Illuminate\Database\Eloquent\Model + * @template TDeclaringModel of \Illuminate\Database\Eloquent\Model + */ trait IsCustomizable { /** * The custom callbacks to run at the end of the get() method. * - * @var list + * @var list): void> */ protected array $postGetCallbacks = []; /** * The custom through key callback for an eager load of the relation. * - * @var callable + * @var callable(string): string */ protected $customThroughKeyCallback = null; /** * The custom constraints callback for an eager load of the relation. * - * @var callable + * @var callable(\Illuminate\Database\Eloquent\Builder, array): void */ protected $customEagerConstraintsCallback = null; /** * The custom matching callbacks for the eagerly loaded results. * - * @var list + * @var list, \Illuminate\Database\Eloquent\Collection, string, string=): array> */ protected array $customEagerMatchingCallbacks = []; /** * Set custom callbacks to run at the end of the get() method. * - * @param list $callbacks + * @param list): void> $callbacks * @return $this */ public function withPostGetCallbacks(array $callbacks): static @@ -48,7 +52,7 @@ public function withPostGetCallbacks(array $callbacks): static /** * Set the custom through key callback for an eager load of the relation. * - * @param callable $callback + * @param callable(string): string $callback * @return $this */ public function withCustomThroughKeyCallback(callable $callback): static @@ -61,7 +65,7 @@ public function withCustomThroughKeyCallback(callable $callback): static /** * Set the custom constraints callback for an eager load of the relation. * - * @param callable $callback + * @param callable(\Illuminate\Database\Eloquent\Builder, array): void $callback * @return $this */ public function withCustomEagerConstraintsCallback(callable $callback): static @@ -74,7 +78,7 @@ public function withCustomEagerConstraintsCallback(callable $callback): static /** * Set a custom matching callback for the eagerly loaded results. * - * @param callable $callback + * @param callable(array, \Illuminate\Database\Eloquent\Collection, string, string=): array $callback * @return $this */ public function withCustomEagerMatchingCallback(callable $callback): static diff --git a/src/Eloquent/Relations/Traits/JoinsThroughParents.php b/src/Eloquent/Relations/Traits/JoinsThroughParents.php index 014f9b1..d0b94b1 100644 --- a/src/Eloquent/Relations/Traits/JoinsThroughParents.php +++ b/src/Eloquent/Relations/Traits/JoinsThroughParents.php @@ -55,6 +55,7 @@ function (JoinClause $join) use ($joins) { if ($this->throughParentInstanceSoftDeletes($throughParent) && method_exists($throughParent, 'getQualifiedDeletedAtColumn')) { + /** @var string $column */ $column = $throughParent->getQualifiedDeletedAtColumn(); $query->withGlobalScope(__CLASS__ . ":$column", function (Builder $query) use ($column) { diff --git a/src/HasManyDeep.php b/src/HasManyDeep.php index df09356..8b1dac3 100644 --- a/src/HasManyDeep.php +++ b/src/HasManyDeep.php @@ -31,6 +31,7 @@ class HasManyDeep extends HasManyThrough implements ConcatenableRelation use HasEagerLoading; use HasExistenceQueries; use IsConcatenable; + /** @use \Staudenmeir\EloquentHasManyDeep\Eloquent\Relations\Traits\IsCustomizable */ use IsCustomizable; use JoinsThroughParents; /** @use \Staudenmeir\EloquentHasManyDeep\Eloquent\Relations\Traits\RetrievesIntermediateTables */