Skip to content

Commit

Permalink
Fix cs and phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
bastien-phi committed Dec 30, 2024
1 parent bdcc13c commit a7761f7
Show file tree
Hide file tree
Showing 19 changed files with 124 additions and 85 deletions.
107 changes: 73 additions & 34 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,136 +1,175 @@
parameters:
ignoreErrors:
-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Actions\\\\FindFactories\\:\\:execute\\(\\) return type with generic class Illuminate\\\\Support\\\\Collection does not specify its types\\: TKey, TValue$#"
message: '#^Parameter \#1 \$view of function view expects view\-string\|null, string given\.$#'
identifier: argument.type
count: 1
path: src/Console/MetaCommand.php

-
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Factories\\Actions\\FindFactories\:\:execute\(\) return type with generic class Illuminate\\Support\\Collection does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/Domain/Factories/Actions/FindFactories.php

-
message: "#^Parameter \\#1 \\$fqcn of class Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Entities\\\\Factory constructor expects class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\Factory\\>, class\\-string given\\.$#"
message: '#^Parameter \#1 \$fqcn of class Soyhuce\\NextIdeHelper\\Domain\\Factories\\Entities\\Factory constructor expects class\-string\<Illuminate\\Database\\Eloquent\\Factories\\Factory\>, class\-string given\.$#'
identifier: argument.type
count: 1
path: src/Domain/Factories/Actions/FindFactories.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Actions\\\\ResolveModels\\:\\:execute\\(\\) has parameter \\$factories with generic class Illuminate\\\\Support\\\\Collection but does not specify its types\\: TKey, TValue$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Factories\\Actions\\ResolveModels\:\:execute\(\) has parameter \$factories with generic class Illuminate\\Support\\Collection but does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/Domain/Factories/Actions/ResolveModels.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Entities\\\\Factory\\:\\:__construct\\(\\) has parameter \\$fqcn with generic class Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\Factory but does not specify its types\\: TModel$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Factories\\Entities\\Factory\:\:__construct\(\) has parameter \$fqcn with generic class Illuminate\\Database\\Eloquent\\Factories\\Factory but does not specify its types\: TModel$#'
identifier: missingType.generics
count: 1
path: src/Domain/Factories/Entities/Factory.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Entities\\\\Factory\\:\\:instance\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\Factory does not specify its types\\: TModel$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Factories\\Entities\\Factory\:\:instance\(\) return type with generic class Illuminate\\Database\\Eloquent\\Factories\\Factory does not specify its types\: TModel$#'
identifier: missingType.generics
count: 1
path: src/Domain/Factories/Entities/Factory.php

-
message: "#^Property Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Entities\\\\Factory\\:\\:\\$extraMethods with generic class Illuminate\\\\Support\\\\Collection does not specify its types\\: TKey, TValue$#"
message: '#^Property Soyhuce\\NextIdeHelper\\Domain\\Factories\\Entities\\Factory\:\:\$extraMethods with generic class Illuminate\\Support\\Collection does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/Domain/Factories/Entities/Factory.php

-
message: "#^Property Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Entities\\\\Factory\\:\\:\\$fqcn with generic class Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\Factory does not specify its types\\: TModel$#"
message: '#^Property Soyhuce\\NextIdeHelper\\Domain\\Factories\\Entities\\Factory\:\:\$fqcn with generic class Illuminate\\Database\\Eloquent\\Factories\\Factory does not specify its types\: TModel$#'
identifier: missingType.generics
count: 1
path: src/Domain/Factories/Entities/Factory.php

-
message: "#^Property Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Factories\\\\Entities\\\\Factory\\:\\:\\$instance with generic class Illuminate\\\\Database\\\\Eloquent\\\\Factories\\\\Factory does not specify its types\\: TModel$#"
message: '#^Property Soyhuce\\NextIdeHelper\\Domain\\Factories\\Entities\\Factory\:\:\$instance with generic class Illuminate\\Database\\Eloquent\\Factories\\Factory does not specify its types\: TModel$#'
identifier: missingType.generics
count: 1
path: src/Domain/Factories/Entities/Factory.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Macros\\\\Actions\\\\FindMacroableClasses\\:\\:execute\\(\\) return type with generic class Illuminate\\\\Support\\\\Collection does not specify its types\\: TKey, TValue$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Macros\\Actions\\FindMacroableClasses\:\:execute\(\) return type with generic class Illuminate\\Support\\Collection does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/Domain/Macros/Actions/FindMacroableClasses.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Macros\\\\Output\\\\MacrosHelperFile\\:\\:__construct\\(\\) has parameter \\$class with generic class ReflectionClass but does not specify its types\\: T$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Macros\\Output\\MacrosHelperFile\:\:__construct\(\) has parameter \$class with generic class ReflectionClass but does not specify its types\: T$#'
identifier: missingType.generics
count: 1
path: src/Domain/Macros/Output/MacrosHelperFile.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Macros\\\\Output\\\\MacrosHelperFile\\:\\:constructor\\(\\) has parameter \\$class with generic class ReflectionClass but does not specify its types\\: T$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Macros\\Output\\MacrosHelperFile\:\:constructor\(\) has parameter \$class with generic class ReflectionClass but does not specify its types\: T$#'
identifier: missingType.generics
count: 1
path: src/Domain/Macros/Output/MacrosHelperFile.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Meta\\\\Actions\\\\ResolveContainerBindings\\:\\:execute\\(\\) return type with generic class Illuminate\\\\Support\\\\Collection does not specify its types\\: TKey, TValue$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Meta\\Actions\\ResolveContainerBindings\:\:execute\(\) return type with generic class Illuminate\\Support\\Collection does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/Domain/Meta/Actions/ResolveContainerBindings.php

-
message: "#^Parameter \\#1 \\$fqcn of class Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Models\\\\Entities\\\\Model constructor expects class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Model\\>, class\\-string given\\.$#"
message: '#^Parameter \#1 \$fqcn of class Soyhuce\\NextIdeHelper\\Domain\\Models\\Entities\\Model constructor expects class\-string\<Illuminate\\Database\\Eloquent\\Model\>, class\-string given\.$#'
identifier: argument.type
count: 1
path: src/Domain/Models/Actions/FindModels.php

-
message: "#^PHPDoc tag @var contains generic class Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\Relation but does not specify its types\\: TRelatedModel$#"
message: '#^Call to an undefined static method Illuminate\\Database\\Eloquent\\Model\:\:factory\(\)\.$#'
identifier: staticMethod.notFound
count: 1
path: src/Domain/Models/Actions/ResolveModelRelations.php
path: src/Domain/Models/Output/ModelDocBlock.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Models\\\\Entities\\\\QueryBuilder\\:\\:__construct\\(\\) has parameter \\$fqcn with generic class Illuminate\\\\Database\\\\Eloquent\\\\Builder but does not specify its types\\: TModelClass$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Models\\Output\\QueryBuilderDocBlock\:\:attributeScopes\(\) should return Illuminate\\Support\\Collection\<int, string\> but returns Illuminate\\Support\\Collection\<int, non\-falsy\-string\>\.$#'
identifier: return.type
count: 1
path: src/Domain/Models/Entities/QueryBuilder.php
path: src/Domain/Models/Output/QueryBuilderDocBlock.php

-
message: "#^Property Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Models\\\\Entities\\\\QueryBuilder\\:\\:\\$fqcn with generic class Illuminate\\\\Database\\\\Eloquent\\\\Builder does not specify its types\\: TModelClass$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Models\\Output\\QueryBuilderDocBlock\:\:resultMethods\(\) should return Illuminate\\Support\\Collection\<int, string\> but returns Illuminate\\Support\\Collection\<int, non\-falsy\-string\>\.$#'
identifier: return.type
count: 1
path: src/Domain/Models/Entities/QueryBuilder.php
path: src/Domain/Models/Output/QueryBuilderDocBlock.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Models\\\\Entities\\\\Relation\\:\\:eloquentRelation\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\Relation does not specify its types\\: TRelatedModel$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Models\\Output\\QueryBuilderDocBlock\:\:scopeMethods\(\) should return Illuminate\\Support\\Collection\<int, string\> but returns Illuminate\\Support\\Collection\<int, non\-falsy\-string\>\.$#'
identifier: return.type
count: 1
path: src/Domain/Models/Entities/Relation.php
path: src/Domain/Models/Output/QueryBuilderDocBlock.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Domain\\\\Models\\\\Entities\\\\Relation\\:\\:isNullable\\(\\) has parameter \\$relation with generic class Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\Relation but does not specify its types\\: TRelatedModel$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Models\\Output\\QueryBuilderDocBlock\:\:softDeletesMethods\(\) should return Illuminate\\Support\\Collection\<int, string\> but returns Illuminate\\Support\\Collection\<int, non\-falsy\-string\>\.$#'
identifier: return.type
count: 1
path: src/Domain/Models/Entities/Relation.php
path: src/Domain/Models/Output/QueryBuilderDocBlock.php

-
message: "#^Call to an undefined static method Illuminate\\\\Database\\\\Eloquent\\\\Model\\:\\:factory\\(\\)\\.$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Domain\\Models\\Output\\QueryBuilderDocBlock\:\:templateBlock\(\) should return Illuminate\\Support\\Collection\<int, string\> but returns Illuminate\\Support\\Collection\<int, non\-falsy\-string\>\.$#'
identifier: return.type
count: 1
path: src/Domain/Models/Output/ModelDocBlock.php
path: src/Domain/Models/Output/QueryBuilderDocBlock.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Entities\\\\Klass\\:\\:addDocTags\\(\\) has parameter \\$docTags with generic class Illuminate\\\\Support\\\\Collection but does not specify its types\\: TKey, TValue$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Entities\\Klass\:\:addDocTags\(\) has parameter \$docTags with generic class Illuminate\\Support\\Collection but does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/Entities/Klass.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Support\\\\Output\\\\IdeHelperClass\\:\\:eloquentBuilder\\(\\) return type with generic class Illuminate\\\\Database\\\\Eloquent\\\\Builder does not specify its types\\: TModelClass$#"
message: '#^Parameter \#1 \$items of method Illuminate\\Support\\Collection\<int,string\>\:\:merge\(\) expects Illuminate\\Contracts\\Support\\Arrayable\<int, non\-falsy\-string\>\|iterable\<int, non\-falsy\-string\>, Illuminate\\Support\\Collection\<int, string\> given\.$#'
identifier: argument.type
count: 1
path: src/Support/Output/IdeHelperClass.php
path: src/Entities/Nemespace.php

-
message: '#^Parameter \#1 \$items of method Illuminate\\Support\\Collection\<int,string\>\:\:merge\(\) expects Illuminate\\Contracts\\Support\\Arrayable\<int, non\-falsy\-string\>\|iterable\<int, non\-falsy\-string\>, Illuminate\\Support\\Collection\<string, string\> given\.$#'
identifier: argument.type
count: 1
path: src/Entities/Nemespace.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Support\\\\Output\\\\IdeHelperClass\\:\\:eloquentBuilder\\(\\) should return class\\-string\\<Illuminate\\\\Database\\\\Eloquent\\\\Builder\\> but returns string\\.$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Support\\Output\\IdeHelperClass\:\:eloquentBuilder\(\) should return class\-string\<Illuminate\\Database\\Eloquent\\Builder\<Illuminate\\Database\\Eloquent\\Model\>\> but returns string\.$#'
identifier: return.type
count: 1
path: src/Support/Output/IdeHelperClass.php

-
message: "#^Parameter \\#1 \\$string of function ltrim expects string, string\\|null given\\.$#"
message: '#^Parameter \#1 \$value of static method Illuminate\\Support\\Str\:\:length\(\) expects string, string\|null given\.$#'
identifier: argument.type
count: 1
path: src/Support/Reflection/FunctionReflection.php

-
message: "#^Parameter \\#1 \\$value of static method Illuminate\\\\Support\\\\Str\\:\\:length\\(\\) expects string, string\\|null given\\.$#"
message: '#^Parameter \#1 \$value of static method Illuminate\\Support\\Str\:\:ltrim\(\) expects string, string\|null given\.$#'
identifier: argument.type
count: 1
path: src/Support/Reflection/FunctionReflection.php

-
message: "#^Parameter \\#1 \\$callback of method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),ReflectionIntersectionType\\|ReflectionNamedType\\>\\:\\:map\\(\\) expects callable\\(ReflectionIntersectionType\\|ReflectionNamedType, int\\|string\\)\\: string, Closure\\(ReflectionNamedType\\)\\: string given\\.$#"
message: '#^Parameter \#1 \$callback of method Illuminate\\Support\\Collection\<\(int\|string\),ReflectionIntersectionType\|ReflectionNamedType\>\:\:map\(\) expects callable\(ReflectionIntersectionType\|ReflectionNamedType, int\|string\)\: string, Closure\(ReflectionNamedType\)\: string given\.$#'
identifier: argument.type
count: 1
path: src/Support/Reflection/TypeReflection.php

-
message: "#^Method Soyhuce\\\\NextIdeHelper\\\\Support\\\\Type\\:\\:qualify\\(\\) should return T of string but returns string\\.$#"
message: '#^Method Soyhuce\\NextIdeHelper\\Support\\Type\:\:qualify\(\) should return T of string but returns string\.$#'
identifier: return.type
count: 2
path: src/Support/Type.php

-
message: "#^Parameter \\#1 \\$key of method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),string\\>\\:\\:contains\\(\\) expects \\(callable\\(string, int\\|string\\)\\: bool\\)\\|string, Closure\\(string\\)\\: \\(0\\|1\\|false\\) given\\.$#"
message: '#^Parameter \#1 \$key of method Illuminate\\Support\\Collection\<\(int\|string\),string\>\:\:contains\(\) expects \(callable\(string, int\|string\)\: bool\)\|string, Closure\(string\)\: \(0\|1\|false\) given\.$#'
identifier: argument.type
count: 1
path: src/Support/Type.php
2 changes: 1 addition & 1 deletion src/Console/AllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function handle(Kernel $console): void
}

/**
* @return array<class-string<\Illuminate\Console\Command>>
* @return array<class-string<Command>>
*/
private function resolveCommands(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function handle(FindModels $findModels): void
}

/**
* @return array<\Soyhuce\NextIdeHelper\Contracts\ModelResolver>
* @return array<ModelResolver>
*/
private function resolvers(ModelCollection $models): array
{
Expand All @@ -87,7 +87,7 @@ private function resolvers(ModelCollection $models): array
}

/**
* @return array<int, class-string<\Soyhuce\NextIdeHelper\Contracts\ModelResolver>>
* @return array<int, class-string<ModelResolver>>
*/
private function modelExtensions(): array
{
Expand Down
6 changes: 3 additions & 3 deletions src/Domain/Factories/Entities/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@

class Factory
{
/** @var class-string<\Illuminate\Database\Eloquent\Factories\Factory> */
/** @var class-string<EloquentFactory> */
public string $fqcn;

public string $filePath;

public Model $model;

/** @var \Illuminate\Support\Collection<string> */
/** @var Collection<string> */
public Collection $extraMethods;

private ?EloquentFactory $instance = null;

/**
* @param class-string<\Illuminate\Database\Eloquent\Factories\Factory> $fqcn
* @param class-string<EloquentFactory> $fqcn
*/
public function __construct(string $fqcn, string $filePath)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Domain/Models/Actions/ResolveModelRelations.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Soyhuce\NextIdeHelper\Domain\Models\Actions;

use Exception;
use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Database\Eloquent\Relations\Relation as EloquentRelation;
use ReflectionClass;
use ReflectionMethod;
Expand Down Expand Up @@ -80,7 +81,7 @@ private function isRelationMethod(ReflectionMethod $method): bool
private function findRelatedFromRelation(Model $model, string $method): Model
{
try {
/** @var EloquentRelation */
/** @var EloquentRelation<EloquentModel, EloquentModel, mixed> $relation */
$relation = $model->instance()->{$method}();
} catch (Exception) {
throw new UnsupportedRelation();
Expand All @@ -97,7 +98,7 @@ private function findRelatedFromRelation(Model $model, string $method): Model
}

/**
* @param class-string<\Illuminate\Database\Eloquent\Model> $class
* @param class-string<EloquentModel> $class
*/
private function resolveOutsideModel(string $class): Model
{
Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Models/AttributeTypeCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private function isCustomCast(string $castType): bool
}

/**
* @param class-string<\Illuminate\Contracts\Database\Eloquent\CastsAttributes<mixed, mixed>> $caster
* @param class-string<CastsAttributes<mixed, mixed>> $caster
*/
private function resolveCustomCast(string $caster): string
{
Expand Down
6 changes: 3 additions & 3 deletions src/Domain/Models/Entities/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class Model
{
/** @var class-string<\Illuminate\Database\Eloquent\Model> */
/** @var class-string<EloquentModel> */
public string $fqcn;

public string $filePath;
Expand All @@ -25,13 +25,13 @@ class Model

public RelationCollection $relations;

/** @var array<\Soyhuce\NextIdeHelper\Entities\Method> */
/** @var array<Method> */
public array $scopes = [];

private ?EloquentModel $instance = null;

/**
* @param class-string<\Illuminate\Database\Eloquent\Model> $fqcn
* @param class-string<EloquentModel> $fqcn
*/
public function __construct(string $fqcn, string $filePath)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Domain/Models/Entities/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
namespace Soyhuce\NextIdeHelper\Domain\Models\Entities;

use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Eloquent\Model as EloquentModel;
use Illuminate\Support\Collection;
use Soyhuce\NextIdeHelper\Support\Type;

class QueryBuilder
{
/** @var class-string<\Illuminate\Database\Eloquent\Builder> */
/** @var class-string<EloquentBuilder<EloquentModel>> */
public string $fqcn;

public string $filePath;

/** @var \Illuminate\Support\Collection<int, string> */
/** @var Collection<int, string> */
public Collection $extras;

/**
* @param class-string<\Illuminate\Database\Eloquent\Builder> $fqcn
* @param class-string<EloquentBuilder<EloquentModel>> $fqcn
*/
public function __construct(string $fqcn, string $filePath)
{
Expand Down
Loading

0 comments on commit a7761f7

Please sign in to comment.