Skip to content

Commit

Permalink
PHPStan fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
LastDragon-ru committed Sep 20, 2024
1 parent 5b80fa0 commit 867f9a1
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestObject extends Model {

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
* @var string
* @var ?string
*/
protected $table = 'test_objects';

Expand Down
5 changes: 5 additions & 0 deletions packages/graphql/src/Builder/Directives/HandlerDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ public function handleBuilder($builder, mixed $value): EloquentBuilder|QueryBuil
return $this->handleAnyBuilder($builder, $value);
}

/**
* @param ScoutBuilder<Model> $builder
*
* @return ScoutBuilder<Model>
*/
public function handleScoutBuilder(ScoutBuilder $builder, mixed $value): ScoutBuilder {
return $this->handleAnyBuilder($builder, $value);
}
Expand Down
16 changes: 8 additions & 8 deletions packages/graphql/src/SearchBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ public function testHandleBuilderV5Compat(
}

/**
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder<EloquentModel> $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderHandleScoutBuilder')]
#[RequiresLaravelScout]
Expand Down Expand Up @@ -483,10 +483,10 @@ static function (MockInterface $mock) use ($resolver): void {
/**
* @deprecated 5.5.0
*
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder<EloquentModel> $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderHandleScoutBuilderV5Compat')]
#[RequiresLaravelScout]
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql/src/SearchBy/Operators/Comparison/EqualTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public function testCall(
}

/**
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder<Model> $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderCallScout')]
#[RequiresLaravelScout]
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql/src/SearchBy/Operators/Comparison/InTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public function testCall(
}

/**
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder<Model> $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderCallScout')]
#[RequiresLaravelScout]
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql/src/SearchBy/Operators/Comparison/NotInTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ public function testCall(
}

/**
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder<Model> $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderCallScout')]
#[RequiresLaravelScout]
Expand Down
12 changes: 6 additions & 6 deletions packages/graphql/src/SearchBy/Operators/Logical/AllOfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ public function testCall(
}

/**
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed> $expected
* @param Closure(static): ScoutBuilder<Model> $builderFactory
* @param Closure(static): Argument $argumentFactory
* @param Closure(static): Context|null $contextFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderCallScout')]
#[RequiresLaravelScout]
Expand Down
16 changes: 8 additions & 8 deletions packages/graphql/src/SortBy/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ public function testHandleBuilderV5Compat(
}

/**
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder<EloquentModel> $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderHandleScoutBuilder')]
#[RequiresLaravelScout]
Expand Down Expand Up @@ -493,10 +493,10 @@ static function (MockInterface $mock) use ($resolver): void {
/**
* @deprecated 5.5.0
*
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
* @param array<string, mixed>|Exception $expected
* @param Closure(static): ScoutBuilder<EloquentModel> $builderFactory
* @param Closure(object, Field): string|null $resolver
* @param Closure():FieldResolver|null $fieldResolver
*/
#[DataProvider('dataProviderHandleScoutBuilderV5Compat')]
#[RequiresLaravelScout]
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/src/SortBy/Sorters/ScoutSorter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LastDragon_ru\LaraASP\GraphQL\SortBy\Sorters;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Builder as ScoutBuilder;
use LastDragon_ru\LaraASP\GraphQL\Builder\Contracts\BuilderFieldResolver;
use LastDragon_ru\LaraASP\GraphQL\Builder\Field;
Expand All @@ -12,7 +13,7 @@
use Override;

/**
* @implements Sorter<ScoutBuilder>
* @implements Sorter<ScoutBuilder<Model>>
*/
class ScoutSorter implements Sorter {
public function __construct(
Expand Down
8 changes: 4 additions & 4 deletions packages/graphql/src/Stream/Directives/DirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,28 +1181,28 @@ public function getPreviousOffset(): ?StreamOffset {
}

/**
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder> $stream
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder<EloquentModel>> $stream
*/
public function getInternalBuilder(Stream $stream): object {
return $stream->builder;
}

/**
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder> $stream
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder<EloquentModel>> $stream
*/
public function getInternalKey(Stream $stream): string {
return $stream->key;
}

/**
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder> $stream
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder<EloquentModel>> $stream
*/
public function getInternalOffset(Stream $stream): StreamOffset {
return $stream->offset;
}

/**
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder> $stream
* @param Stream<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder<EloquentModel>> $stream
*/
public function getInternalLimit(Stream $stream): int {
return $stream->limit;
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/Stream/StreamFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

/**
* @internal
* @implements StreamFactoryContract<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder>
* @implements StreamFactoryContract<EloquentBuilder<EloquentModel>|QueryBuilder|ScoutBuilder<EloquentModel>>
*/
class StreamFactory implements StreamFactoryContract {
public function __construct() {
Expand Down
3 changes: 2 additions & 1 deletion packages/graphql/src/Stream/Streams/Scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LastDragon_ru\LaraASP\GraphQL\Stream\Streams;

use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Builder as ScoutBuilder;
use LastDragon_ru\LaraASP\Core\Utils\Cast;
use LastDragon_ru\LaraASP\GraphQL\Stream\Offset;
Expand All @@ -13,7 +14,7 @@
use function max;

/**
* @extends Stream<ScoutBuilder>
* @extends Stream<ScoutBuilder<covariant Model>>
*/
class Scout extends Stream {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TestObject extends Model {

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
* @var string
* @var ?string
*/
protected $table = 'test_objects';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TestObjectSearchable extends Model {

/**
* @phpcsSuppress SlevomatCodingStandard.TypeHints.PropertyTypeHint.MissingNativeTypeHint
* @var string
* @var ?string
*/
protected $table = 'test_objects';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
*/
class ExposeBuilderDirective extends BaseDirective implements FieldResolver, BuilderInfoProvider {
/**
* @var QueryBuilder|EloquentBuilder<Model>|ScoutBuilder
* @var QueryBuilder|EloquentBuilder<Model>|ScoutBuilder<Model>
*/
public static QueryBuilder|EloquentBuilder|ScoutBuilder $builder;

/**
* @var QueryBuilder|EloquentBuilder<Model>|ScoutBuilder|Relation<Model>|null
* @var QueryBuilder|EloquentBuilder<Model>|ScoutBuilder<Model>|Relation<Model>|null
*/
public static QueryBuilder|EloquentBuilder|ScoutBuilder|Relation|null $result = null;

Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/Testing/Package/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function getGraphQLArgument(
/**
* @template M of EloquentModel
*
* @param QueryBuilder|EloquentBuilder<M>|ScoutBuilder $builder
* @param QueryBuilder|EloquentBuilder<M>|ScoutBuilder<M> $builder
*/
protected function getExposeBuilderDirective(
QueryBuilder|EloquentBuilder|ScoutBuilder $builder,
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/Testing/SchemaBuilderWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function schema(): Schema {
* but the lowest supported version is {@see https://github.com/nuwave/lighthouse/releases/tag/v6.5.0}.
* To avoid the error the {@see Override} is missed.
*
* @phpstan-ignore method.missingOverride
* @phpstan-ignore-next-line
*/
public function schemaHash(): string {
return $this->getSchemaBuilder()->schemaHash();
Expand Down
5 changes: 3 additions & 2 deletions packages/testing/src/Assertions/ScoutAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace LastDragon_ru\LaraASP\Testing\Assertions;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Builder;
use LastDragon_ru\LaraASP\Testing\Utils\Args;
use PHPUnit\Framework\Assert;
Expand All @@ -13,8 +14,8 @@ trait ScoutAssertions {
/**
* Asserts that Scout Query equals Scout Query.
*
* @param Builder|array<string, mixed>|string $expected
* @param Builder|array<string, mixed>|string $actual
* @param Builder<covariant Model>|array<string, mixed>|string $expected
* @param Builder<covariant Model>|array<string, mixed>|string $actual
*/
public static function assertScoutQueryEquals(
Builder|array|string $expected,
Expand Down
15 changes: 15 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ parameters:
count: 1
path: packages/formatter/src/Formatter.php

-
message: "#^Method class@anonymous/packages/graphql/src/Stream/Directives/Directive\\.php\\:476\\:\\:enhanceEloquentBuilder\\(\\) return type with generic class Laravel\\\\Scout\\\\Builder does not specify its types\\: TModel$#"
count: 1
path: packages/graphql/src/Stream/Directives/Directive.php

-
message: "#^Method LastDragon_ru\\\\LaraASP\\\\GraphQL\\\\Testing\\\\Package\\\\Models\\\\Image\\:\\:imageable\\(\\) should return Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphTo\\<LastDragon_ru\\\\LaraASP\\\\GraphQL\\\\Testing\\\\Package\\\\Models\\\\Role\\|LastDragon_ru\\\\LaraASP\\\\GraphQL\\\\Testing\\\\Package\\\\Models\\\\User, LastDragon_ru\\\\LaraASP\\\\GraphQL\\\\Testing\\\\Package\\\\Models\\\\Image\\> but returns Illuminate\\\\Database\\\\Eloquent\\\\Relations\\\\MorphTo\\<Illuminate\\\\Database\\\\Eloquent\\\\Model, LastDragon_ru\\\\LaraASP\\\\GraphQL\\\\Testing\\\\Package\\\\Models\\\\Image\\>\\.$#"
count: 1
Expand All @@ -50,6 +55,11 @@ parameters:
count: 1
path: packages/spa/src/Http/Resources/Resource.php

-
message: "#^Method class@anonymous/packages/spa/src/Http/WithValueProviderTest\\.php\\:50\\:\\:validate\\(\\) has parameter \\$fail with no signature specified for Closure\\.$#"
count: 1
path: packages/spa/src/Http/WithValueProviderTest.php

-
message: "#^Cannot access property \\$id on mixed\\.$#"
count: 1
Expand All @@ -60,6 +70,11 @@ parameters:
count: 1
path: packages/spa/src/Validation/Rules/DateTimeRule.php

-
message: "#^Method LastDragon_ru\\\\LaraASP\\\\Spa\\\\Validation\\\\Rules\\\\Rule\\:\\:validate\\(\\) has parameter \\$fail with no signature specified for Closure\\.$#"
count: 1
path: packages/spa/src/Validation/Rules/Rule.php

-
message: "#^Parameter \\#1 \\$query of method LastDragon_ru\\\\LaraASP\\\\Testing\\\\Comparators\\\\DatabaseQueryComparator\\:\\:normalize\\(\\) expects LastDragon_ru\\\\LaraASP\\\\Testing\\\\Database\\\\QueryLog\\\\Query, mixed given\\.$#"
count: 2
Expand Down

0 comments on commit 867f9a1

Please sign in to comment.