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

Clean up docblocks #2390

Merged
merged 2 commits into from
May 3, 2023
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: 2 additions & 3 deletions src/Console/PrintSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
use GraphQL\Type\Introspection;
use GraphQL\Utils\SchemaPrinter;
use Illuminate\Console\Command;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Filesystem\FilesystemManager;
use Illuminate\Support\Facades\Storage;
use Nuwave\Lighthouse\Federation\FederationPrinter;
use Nuwave\Lighthouse\Schema\AST\ASTCache;
use Nuwave\Lighthouse\Schema\SchemaBuilder;
Expand Down Expand Up @@ -56,9 +54,10 @@ public function handle(ASTCache $cache, FilesystemManager $filesystemManager, Sc

if ($this->option('write')) {
$disk = $this->option('disk');
if (! is_string($disk) && ! is_null($disk)) {
if (! is_string($disk) && ! is_null($disk)) { // @phpstan-ignore-line can be array
$diskType = gettype($disk);
$this->error("Expected option disk to be string or null, got: {$diskType}.");

return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Deprecation/DetectDeprecatedUsage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class DetectDeprecatedUsage extends ValidationRule
/** @var DeprecationHandler */
protected $deprecationHandler;

/** @param DeprecationHandler $deprecationHandler */
/** @param DeprecationHandler $deprecationHandler */
public function __construct(callable $deprecationHandler)
{
$this->deprecationHandler = $deprecationHandler;
}

/** @param DeprecationHandler $deprecationHandler */
/** @param DeprecationHandler $deprecationHandler */
public static function handle(callable $deprecationHandler): void
{
DocumentValidator::addRule(new static($deprecationHandler));
Expand Down
1 change: 0 additions & 1 deletion src/Exceptions/DefinitionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Nuwave\Lighthouse\Exceptions;

use Exception;
use GraphQL\Error\ClientAware;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Execution/Arguments/ArgPartitioner.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static function relationMethods(
/**
* Attach a nested argument resolver to an argument.
*
* @param \ReflectionClass<\Illuminate\Database\Eloquent\Model>|null $model
* @param \ReflectionClass<\Illuminate\Database\Eloquent\Model>|null $model
*/
protected static function attachNestedArgResolver(string $name, Argument &$argument, ?\ReflectionClass $model): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Federation/BatchedEntityResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface BatchedEntityResolver
/**
* Resolve multiple entities of a single type in one batch.
*
* @param array<string, array<string, mixed>> $representations
* @param array<string, array<string, mixed>> $representations
*
* @return iterable<string, mixed> must preserve the count and keys of $representations
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Federation/EntityResolverProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function firstSatisfiedKeyFields(Collection $keyFieldsSelections, array $
?? throw new Error('Representation does not satisfy any set of uniquely identifying keys: ' . \Safe\json_encode($representation));
}

/** @param array<string, mixed> $representation */
/** @param array<string, mixed> $representation */
protected function hydrateExternalFields(Model $model, array $representation, ObjectTypeDefinitionNode $definition): void
{
foreach ($definition->fields as $field) {
Expand Down
4 changes: 2 additions & 2 deletions src/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(
*
* @api
*
* @param array<string, mixed>|null $variables
* @param array<string, mixed>|null $variables
*
* @return array<string, mixed>
*/
Expand Down Expand Up @@ -95,7 +95,7 @@ public function executeQueryString(
* you will probably want to call `->toArray($debug)` on it,
* with $debug being a combination of flags in @see \GraphQL\Error\DebugFlag
*
* @param array<string, mixed>|null $variables
* @param array<string, mixed>|null $variables
*
* @return array<string, mixed>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Pagination/PaginationArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected static function calculateCurrentPage(int $first, int $after, int $defa
*
* @param \Illuminate\Database\Query\Builder|\Laravel\Scout\Builder|\Illuminate\Database\Eloquent\Builder<TModel>|\Illuminate\Database\Eloquent\Relations\Relation<TModel> $builder
*
* @return Paginator<TModel>
* @return \Illuminate\Contracts\Pagination\Paginator<TModel>
*/
public function applyToBuilder(QueryBuilder|ScoutBuilder|EloquentBuilder|Relation $builder): Paginator
{
Expand Down
4 changes: 2 additions & 2 deletions src/Pagination/PaginatorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class PaginatorField
* @return array{
* count: int,
* currentPage: int,
* firstItem: int,
* firstItem: int|null,
* hasMorePages: bool,
* lastItem: int,
* lastItem: int|null,
* lastPage: int,
* perPage: int,
* total: int,
Expand Down
4 changes: 2 additions & 2 deletions src/Pagination/SimplePaginatorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class SimplePaginatorField
* @return array{
* count: int,
* currentPage: int,
* firstItem: int,
* lastItem: int,
* firstItem: int|null,
* lastItem: int|null,
* perPage: int,
* hasMorePages: bool,
* }
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/AST/ASTHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public static function getUnderlyingNamedTypeNode(Node $node): NamedTypeNode
/**
* Extract a named argument from a given directive node.
*
* @param mixed $default is returned if the directive does not have the argument
* @param mixed $default is returned if the directive does not have the argument
*/
public static function directiveArgValue(DirectiveNode $directive, string $name, mixed $default = null): mixed
{
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/AST/ExecutableTypeNodeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
protected TypeRegistry $typeRegistry,
) {}

/** @param \GraphQL\Type\Definition\Type&\GraphQL\Type\Definition\NullableType $type */
/** @param \GraphQL\Type\Definition\Type&\GraphQL\Type\Definition\NullableType $type */
protected function nonNull(mixed $type): NonNull
{
return Type::nonNull($type);
Expand All @@ -22,7 +22,7 @@ protected function nonNull(mixed $type): NonNull
/**
* @template T of \GraphQL\Type\Definition\Type
*
* @param T|callable():T $type
* @param T|callable():T $type
*
* @return \GraphQL\Type\Definition\ListOfType<T>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/AST/FallbackTypeNodeConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function nonNull(mixed $type): NonNull
/**
* @template T of Type
*
* @param T|callable():T $type
* @param T|callable():T $type
*
* @return ListOfType<T>
*/
Expand Down
13 changes: 5 additions & 8 deletions src/Schema/Directives/AggregateDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ public function resolveField(FieldValue $fieldValue): callable
if (is_string($relation)) {
return function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo): Deferred {
$relationBatchLoader = BatchLoaderRegistry::instance(
array_merge(
$this->qualifyPath($args, $resolveInfo),
[$this->function(), $this->column()],
),
[...$this->qualifyPath($args, $resolveInfo), $this->function(), $this->column()],
fn (): RelationBatchLoader => new RelationBatchLoader(
new AggregateModelsLoader(
$this->relation(),
Expand Down Expand Up @@ -144,16 +141,16 @@ public function resolveField(FieldValue $fieldValue): callable
$builderResolver = $this->getResolverFromArgument('builder');

return function (mixed $root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($builderResolver) {
$query = $builderResolver($root, $args, $context, $resolveInfo);
$builder = $builderResolver($root, $args, $context, $resolveInfo);

assert(
$query instanceof QueryBuilder || $query instanceof EloquentBuilder,
$builder instanceof QueryBuilder || $builder instanceof EloquentBuilder,
"The method referenced by the builder argument of the @{$this->name()} directive on {$this->nodeName()} must return a Builder.",
);

$this->makeBuilderDecorator($root, $args, $context, $resolveInfo)($query);
$this->makeBuilderDecorator($root, $args, $context, $resolveInfo)($builder);

return $query->{$this->function()}($this->column());
return $builder->{$this->function()}($this->column());
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Directives/BaseDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function directiveHasArgument(string $name): bool
*
* @api
*
* @param mixed $default Use this over `??` to preserve explicit `null`
* @param mixed $default Use this over `??` to preserve explicit `null`
*
* @return mixed The argument value or the default
*/
Expand Down Expand Up @@ -257,7 +257,7 @@ protected function namespaceModelClass(string $modelClassCandidate): string
*
* @api
*
* @param array<string> $names
* @param array<string> $names
*/
protected function validateMutuallyExclusiveArguments(array $names): void
{
Expand Down
1 change: 0 additions & 1 deletion src/Schema/Directives/ComplexityDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Nuwave\Lighthouse\Schema\Directives;

use Nuwave\Lighthouse\Pagination\PaginationManipulator;
use Nuwave\Lighthouse\Schema\Values\FieldValue;
use Nuwave\Lighthouse\Support\Contracts\ComplexityResolverDirective;
use Nuwave\Lighthouse\Support\Utils;
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/ResolverProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function provideResolver(FieldValue $fieldValue): \Closure
// Return any non-null value to continue nested field resolution
// when the root Query type is returned as part of the result.
if (ASTHelper::getUnderlyingTypeName($fieldValue->getField()) === RootType::QUERY) {
return static fn () => true;
return static fn (): bool => true;
}

return \Closure::fromCallable(
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/TypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function register(Type $type): self
*
* @api
*
* @param callable(): \GraphQL\Type\Definition\Type&\GraphQL\Type\Definition\NamedType $type
* @param callable(): \GraphQL\Type\Definition\Type&\GraphQL\Type\Definition\NamedType $type
*/
public function registerLazy(string $name, callable $type): self
{
Expand Down Expand Up @@ -200,7 +200,7 @@ public function overwrite(Type $type): self
*
* @api
*
* @param callable(): \GraphQL\Type\Definition\Type&\GraphQL\Type\Definition\NamedType $type
* @param callable(): \GraphQL\Type\Definition\Type&\GraphQL\Type\Definition\NamedType $type
*/
public function overwriteLazy(string $name, callable $type): self
{
Expand Down
1 change: 0 additions & 1 deletion src/Validation/RulesGatherer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Nuwave\Lighthouse\Validation;

use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Validation\ValidationRuleParser;
Expand Down
2 changes: 1 addition & 1 deletion src/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function setArgs(ArgumentSet $args): void
* Retrieve the value of an argument or the default.
*
* @param string $key the key of the argument, may use dot notation to get nested values
* @param mixed $default returned in case the argument is not present
* @param mixed $default returned in case the argument is not present
*/
protected function arg(string $key, mixed $default = null): mixed
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function testAggregateWithBuilder(): void
]);
}

/** @param array{difficulty: int, exclude: int} $args */
/** @param array{difficulty: int, exclude: int} $args */
public function builder(mixed $root, array $args): Builder
{
return DB::table('tasks')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function testSocketIDStoredOnSubscribe(): void
$this->assertSame('1234.1234', $createdSubscriber->socket_id);
}

/** @param array<string, mixed> $headers */
/** @param array<string, mixed> $headers */
protected function querySubscription(string $topic = /** @lang GraphQL */ 'taskUpdated(id: 123)', array $headers = []): TestResponse
{
return $this->graphQL(/** @lang GraphQL */ "
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Pagination/PaginationTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class PaginationTypeTest extends TestCase
/**
* @dataProvider invalidPaginationTypes
*
* @param string $type An invalid type
* @param string $type An invalid type
*/
public function testThrowsExceptionForUnsupportedTypes(string $type): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function testPusherNeverUsesLoggerInterface(): void
$this->broadcast($subscriber);
}

/** @param \Nuwave\Lighthouse\Subscriptions\Subscriber&\PHPUnit\Framework\MockObject\MockObject $subscriber */
/** @param \Nuwave\Lighthouse\Subscriptions\Subscriber&\PHPUnit\Framework\MockObject\MockObject $subscriber */
private function broadcast(object $subscriber): void
{
$broadcastManager = $this->app->make(BroadcastManager::class);
Expand Down
6 changes: 3 additions & 3 deletions tests/Utils/Models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function user(): BelongsTo
}

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param \Illuminate\Database\Eloquent\Builder<self> $query
*
* @return \Illuminate\Database\Eloquent\Builder<self>
*/
Expand All @@ -107,7 +107,7 @@ public function scopeCompleted(EloquentBuilder $query): EloquentBuilder
}

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param array<string, int> $args
*
* @return \Illuminate\Database\Eloquent\Builder<self>
Expand All @@ -118,7 +118,7 @@ public function scopeFoo(EloquentBuilder $query, array $args): EloquentBuilder
}

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param iterable<string> $tags
*
* @return \Illuminate\Database\Eloquent\Builder<self>
Expand Down
6 changes: 3 additions & 3 deletions tests/Utils/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public function team(): BelongsTo
}

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param array{company: string} $args
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param array{company: string} $args
*
* @return \Illuminate\Database\Eloquent\Builder<self>
*/
Expand All @@ -132,7 +132,7 @@ public function scopeCompanyName(EloquentBuilder $query, array $args): EloquentB
}

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $query
* @param \Illuminate\Database\Eloquent\Builder<self> $query
*
* @return \Illuminate\Database\Eloquent\Builder<self>
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/Utils/Models/WithEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class WithEnum extends Model
];

/**
* @param \Illuminate\Database\Eloquent\Builder<self> $builder
* @param \Illuminate\Database\Eloquent\Builder<self> $builder
*
* @return \Illuminate\Database\Eloquent\Builder<self>
*/
Expand Down