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

upgrade to phpstan 2 and larastan 3 #273

Merged
merged 4 commits into from
Nov 19, 2024
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: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.0",
"harrygulliford/laravel-firebird": "^3.3",
"larastan/larastan": "2.9.8",
"larastan/larastan": "^3.0",
"laravel/framework": "^11.0",
"mockery/mockery": "^1.5.1",
"orchestra/testbench": "^9.0",
"orchestra/testbench-core": "^9.5",
"phpunit/phpunit": "^11.0",
"singlestoredb/singlestoredb-laravel": "^1.5.4",
"staudenmeir/eloquent-has-many-deep": "^1.20"
Expand Down
3 changes: 3 additions & 0 deletions src/Eloquent/HasGraphRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Staudenmeir\LaravelAdjacencyList\Eloquent\Traits\HasGraphAdjacencyList;
use Staudenmeir\LaravelCte\Eloquent\QueriesExpressions;

/**
* @phpstan-ignore trait.unused
*/
trait HasGraphRelationships
{
use HasGraphAdjacencyList;
Expand Down
3 changes: 3 additions & 0 deletions src/Eloquent/HasRecursiveRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Staudenmeir\LaravelAdjacencyList\Eloquent\Traits\HasAdjacencyList;
use Staudenmeir\LaravelCte\Eloquent\QueriesExpressions;

/**
* @phpstan-ignore trait.unused
*/
trait HasRecursiveRelationships
{
use HasAdjacencyList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function matchResultsForDeepRelationship(
* Build the model dictionary for a deep relation.
*
* @param \Illuminate\Database\Eloquent\Collection<array-key, \Illuminate\Database\Eloquent\Model> $results
* @return array<int|string, list<\Illuminate\Database\Eloquent\Model>>
* @return array<int|string, array<int, \Illuminate\Database\Eloquent\Model>>
*/
protected function buildDictionaryForDeepRelationship(Collection $results): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Eloquent/Relations/Graph/Traits/IsRecursiveRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
/**
* Add the recursive expression for an eager load of the relation.
*
* @param list<TDeclaringModel> $models
* @param array<int, TDeclaringModel> $models
* @param string $column
* @return void
*/
Expand Down Expand Up @@ -80,7 +80,7 @@ protected function addEagerExpression(array $models, string $column): void
* Build model dictionary.
*
* @param \Illuminate\Database\Eloquent\Collection<array-key, \Illuminate\Database\Eloquent\Model> $results
* @return array<int|string, list<\Illuminate\Database\Eloquent\Model>>
* @return array<int|string, array<int, \Illuminate\Database\Eloquent\Model>>
*/
protected function buildDictionary(Collection $results)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function matchResultsForDeepRelationship(
* Build the model dictionary for a deep relation.
*
* @param \Illuminate\Database\Eloquent\Collection<array-key, \Illuminate\Database\Eloquent\Model> $results
* @return array<int|string, list<\Illuminate\Database\Eloquent\Model>>
* @return array<int|string, array<int, \Illuminate\Database\Eloquent\Model>>
*/
protected function buildDictionaryForDeepRelationship(Collection $results): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function matchResultsForDeepRelationship(
* Build the model dictionary for a deep relation.
*
* @param \Illuminate\Database\Eloquent\Collection<array-key, \Illuminate\Database\Eloquent\Model> $results
* @return array<int|string, list<\Illuminate\Database\Eloquent\Model>>
* @return array<int|string, array<int, \Illuminate\Database\Eloquent\Model>>
*/
protected function buildDictionaryForDeepRelationship(Collection $results): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Relations/Traits/IsOfDescendantsRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function addEagerConstraints(array $models)
* Set the where clause on the recursive expression query for an eager load of the relation.
*
* @param \Staudenmeir\LaravelAdjacencyList\Eloquent\Builder<\Illuminate\Database\Eloquent\Model> $query
* @param list<TDeclaringModel> $models
* @param array<int, TDeclaringModel> $models
* @return void
*/
public function addEagerExpressionWhereConstraints(Builder $query, array $models)
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Relations/Traits/IsRecursiveRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(Builder $query, Model $parent, $foreignKey, $localKe
* Build model dictionary.
*
* @param \Illuminate\Database\Eloquent\Collection<array-key, TRelatedModel> $results
* @return array<int|string, list<TRelatedModel>>
* @return array<int|string, array<int, TRelatedModel>>
*/
protected function buildDictionary(Collection $results)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Traits/BuildsAdjacencyListQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getModels($columns = ['*'])
/**
* Replace the separator in a PostgreSQL path column.
*
* @param list<object> $items
* @param array<int, object> $items
* @param string $path
* @param string $separator
* @return void
Expand Down
2 changes: 2 additions & 0 deletions src/Eloquent/Traits/HasAdjacencyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
* @property-read static $rootAncestorOrSelf
* @property-read Collection<int, static> $siblings
* @property-read Collection<int, static> $siblingsAndSelf
*
* @phpstan-ignore trait.unused
*/
trait HasAdjacencyList
{
Expand Down
2 changes: 2 additions & 0 deletions src/Eloquent/Traits/HasGraphAdjacencyList.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* @property-read Collection<int, static> $descendantsAndSelf
* @property-read Collection<int, static> $parents
* @property-read Collection<int, static> $parentsAndSelf
*
* @phpstan-ignore trait.unused
*/
trait HasGraphAdjacencyList
{
Expand Down
3 changes: 3 additions & 0 deletions src/Eloquent/Traits/HasGraphRelationshipScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\Support\Collection;
use Staudenmeir\LaravelAdjacencyList\Query\Grammars\ExpressionGrammar;

/**
* @phpstan-ignore trait.unused
*/
trait HasGraphRelationshipScopes
{
/**
Expand Down
25 changes: 14 additions & 11 deletions src/Eloquent/Traits/HasOfDescendantsRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants;
use Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants;

/**
* @phpstan-ignore trait.unused
*/
trait HasOfDescendantsRelationships
{
/**
Expand All @@ -19,7 +22,7 @@ trait HasOfDescendantsRelationships
* @param class-string<TRelatedModel> $related
* @param string|null $foreignKey
* @param string|null $localKey
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<TRelatedModel, $this>
*/
public function hasManyOfDescendants($related, $foreignKey = null, $localKey = null)
{
Expand Down Expand Up @@ -47,7 +50,7 @@ public function hasManyOfDescendants($related, $foreignKey = null, $localKey = n
* @param class-string<TRelatedModel> $related
* @param string|null $foreignKey
* @param string|null $localKey
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<TRelatedModel, $this>
*/
public function hasManyOfDescendantsAndSelf($related, $foreignKey = null, $localKey = null)
{
Expand Down Expand Up @@ -77,7 +80,7 @@ public function hasManyOfDescendantsAndSelf($related, $foreignKey = null, $local
* @param string $foreignKey
* @param string $localKey
* @param bool $andSelf
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\HasManyOfDescendants<TRelatedModel, $this>
*/
protected function newHasManyOfDescendants(Builder $query, Model $parent, $foreignKey, $localKey, $andSelf)
{
Expand All @@ -95,7 +98,7 @@ protected function newHasManyOfDescendants(Builder $query, Model $parent, $forei
* @param string|null $relatedPivotKey
* @param string|null $parentKey
* @param string|null $relatedKey
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<TRelatedModel, $this>
*/
public function belongsToManyOfDescendants(
$related,
Expand Down Expand Up @@ -139,7 +142,7 @@ public function belongsToManyOfDescendants(
* @param string|null $relatedPivotKey
* @param string|null $parentKey
* @param string|null $relatedKey
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<TRelatedModel, $this>
*/
public function belongsToManyOfDescendantsAndSelf(
$related,
Expand Down Expand Up @@ -185,7 +188,7 @@ public function belongsToManyOfDescendantsAndSelf(
* @param string $parentKey
* @param string $relatedKey
* @param bool $andSelf
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\BelongsToManyOfDescendants<TRelatedModel, $this>
*/
protected function newBelongsToManyOfDescendants(
Builder $query,
Expand Down Expand Up @@ -222,7 +225,7 @@ protected function newBelongsToManyOfDescendants(
* @param string|null $parentKey
* @param string|null $relatedKey
* @param bool $inverse
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel, $this>
*/
public function morphToManyOfDescendants(
$related,
Expand Down Expand Up @@ -276,7 +279,7 @@ public function morphToManyOfDescendants(
* @param string|null $parentKey
* @param string|null $relatedKey
* @param bool $inverse
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel, $this>
*/
public function morphToManyOfDescendantsAndSelf(
$related,
Expand Down Expand Up @@ -332,7 +335,7 @@ public function morphToManyOfDescendantsAndSelf(
* @param string $relatedKey
* @param bool $inverse
* @param bool $andSelf
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel, $this>
*/
protected function newMorphToManyOfDescendants(
Builder $query,
Expand Down Expand Up @@ -372,7 +375,7 @@ protected function newMorphToManyOfDescendants(
* @param string|null $relatedPivotKey
* @param string|null $parentKey
* @param string|null $relatedKey
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel, $this>
*/
public function morphedByManyOfDescendants(
$related,
Expand Down Expand Up @@ -411,7 +414,7 @@ public function morphedByManyOfDescendants(
* @param string|null $relatedPivotKey
* @param string|null $parentKey
* @param string|null $relatedKey
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel>
* @return \Staudenmeir\LaravelAdjacencyList\Eloquent\Relations\MorphToManyOfDescendants<TRelatedModel, $this>
*/
public function morphedByManyOfDescendantsAndSelf(
$related,
Expand Down
3 changes: 3 additions & 0 deletions src/Eloquent/Traits/HasQueryConstraints.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Staudenmeir\LaravelAdjacencyList\Eloquent\Traits;

/**
* @phpstan-ignore trait.unused
*/
trait HasQueryConstraints
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Eloquent/Traits/HasRecursiveRelationshipHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Database\Eloquent\Model;

/**
* @phpstan-ignore trait.unused
*/
trait HasRecursiveRelationshipHelpers
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Eloquent/Traits/HasRecursiveRelationshipScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Illuminate\Database\Query\JoinClause;
use Staudenmeir\LaravelAdjacencyList\Query\Grammars\ExpressionGrammar;

/**
* @phpstan-ignore trait.unused
*/
trait HasRecursiveRelationshipScopes
{
/**
Expand Down
4 changes: 2 additions & 2 deletions src/Query/Grammars/ExpressionGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface ExpressionGrammar
/**
* Compile an initial path.
*
* @param string $column
* @param string|\Illuminate\Contracts\Database\Query\Expression $column
* @param string $alias
* @return string
*/
Expand All @@ -18,7 +18,7 @@ public function compileInitialPath($column, $alias);
/**
* Compile a recursive path.
*
* @param string $column
* @param string|\Illuminate\Contracts\Database\Query\Expression $column
* @param string $alias
* @param bool $reverse
* @return string
Expand Down
2 changes: 2 additions & 0 deletions src/Query/Grammars/FirebirdGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class FirebirdGrammar extends Base implements ExpressionGrammar
{
use OrdersByPath;

/** @inheritDoc */
public function compileInitialPath($column, $alias)
{
return 'cast(' . $this->wrap($column) . ' as varchar(8191)) as ' . $this->wrap($alias);
}

/** @inheritDoc */
public function compileRecursivePath($column, $alias, bool $reverse = false)
{
$wrappedColumn = $this->wrap($column);
Expand Down
17 changes: 2 additions & 15 deletions src/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ class PostgresGrammar extends Base implements ExpressionGrammar
{
use OrdersByPath;

/**
* Compile an initial path.
*
* @param string $column
* @param string $alias
* @return string
*/
/** @inheritDoc */
public function compileInitialPath($column, $alias)
{
if (is_string($column) && $this->model->isIntegerAttribute($column)) {
Expand All @@ -25,14 +19,7 @@ public function compileInitialPath($column, $alias)
return 'array[('.$this->wrap($column)." || '')::varchar] as ".$this->wrap($alias);
}

/**
* Compile a recursive path.
*
* @param string $column
* @param string $alias
* @param bool $reverse
* @return string
*/
/** @inheritDoc */
public function compileRecursivePath($column, $alias, bool $reverse = false)
{
$wrappedColumn = $this->wrap($column);
Expand Down
17 changes: 2 additions & 15 deletions src/Query/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,13 @@ class SQLiteGrammar extends Base implements ExpressionGrammar
{
use OrdersByPath;

/**
* Compile an initial path.
*
* @param string $column
* @param string $alias
* @return string
*/
/** @inheritDoc */
public function compileInitialPath($column, $alias)
{
return 'cast(' . $this->wrap($column) . ' as text) as ' . $this->wrap($alias);
}

/**
* Compile a recursive path.
*
* @param string $column
* @param string $alias
* @param bool $reverse
* @return string
*/
/** @inheritDoc */
public function compileRecursivePath($column, $alias, bool $reverse = false)
{
$wrappedColumn = $this->wrap($column);
Expand Down
17 changes: 2 additions & 15 deletions src/Query/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,13 @@ class SqlServerGrammar extends Base implements ExpressionGrammar
{
use OrdersByPath;

/**
* Compile an initial path.
*
* @param string $column
* @param string $alias
* @return string
*/
/** @inheritDoc */
public function compileInitialPath($column, $alias)
{
return 'cast('.$this->wrap($column).' as varchar(max)) as '.$this->wrap($alias);
}

/**
* Compile a recursive path.
*
* @param string $column
* @param string $alias
* @param bool $reverse
* @return string
*/
/** @inheritDoc */
public function compileRecursivePath($column, $alias, bool $reverse = false)
{
$wrappedColumn = $this->wrap($column);
Expand Down
Loading