Skip to content

Commit

Permalink
Fix PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
remipelhate committed Dec 27, 2024
1 parent 8080404 commit f0ddbeb
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/Bind/BindDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use GraphQL\Language\AST\FieldDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
use GraphQL\Language\AST\InputValueDefinitionNode;
use GraphQL\Language\AST\NamedTypeNode;
use GraphQL\Language\AST\TypeNode;
use Illuminate\Database\Eloquent\Model;
use Nuwave\Lighthouse\Exceptions\DefinitionException;
Expand All @@ -17,7 +18,7 @@
use function property_exists;

/**
* @template TClass
* @template-covariant TClass of object
* @property-read class-string<TClass> $class
* @property-read string $column
* @property-read array<string> $with
Expand Down Expand Up @@ -80,7 +81,11 @@ private function valueType(TypeNode $typeNode): string
return $this->valueType($typeNode->type);
}

return $typeNode->name->value;
if ($typeNode instanceof NamedTypeNode) {
return $typeNode->name->value;
}

return '';
}

public function isModelBinding(): bool
Expand Down
6 changes: 6 additions & 0 deletions src/Bind/BindDirective.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@

class BindDirective extends BaseDirective implements ArgumentValidation, ArgTransformerDirective, ArgDirectiveForArray, ArgManipulator, InputFieldManipulator
{
/**
* @var \Nuwave\Lighthouse\Bind\BindDefinition<object>|null
*/
private ?BindDefinition $definition = null;
private mixed $binding;

Expand Down Expand Up @@ -66,6 +69,9 @@ class: String!
GRAPHQL;
}

/**
* @return \Nuwave\Lighthouse\Bind\BindDefinition<object>
*/
private function bindDefinition(): BindDefinition
{
return $this->definition ??= new BindDefinition(
Expand Down
11 changes: 8 additions & 3 deletions src/Bind/ModelBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
class ModelBinding
{
/**
* @param int|string|array<int|string> $value
* @param \Nuwave\Lighthouse\Bind\BindDefinition<\Illuminate\Database\Eloquent\Model> $definition
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection<string, \Illuminate\Database\Eloquent\Model>|null
*/
public function __invoke(int|string|array $value, BindDefinition $definition): Model|EloquentCollection|null
{
Expand All @@ -30,7 +32,7 @@ public function __invoke(int|string|array $value, BindDefinition $definition): M
}

/**
* @param \Illuminate\Database\Eloquent\Collection<\Illuminate\Database\Eloquent\Model> $results
* @param \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model> $results
*/
private function modelInstance(EloquentCollection $results): ?Model
{
Expand All @@ -45,8 +47,11 @@ private function modelInstance(EloquentCollection $results): ?Model
* Binding collections should be returned with the original values
* as keys to allow us to validate the binding when non-optional.
* @see \Nuwave\Lighthouse\Bind\BindDirective::rules()
* @param \Illuminate\Database\Eloquent\Collection<\Illuminate\Database\Eloquent\Model> $results
* @return \Illuminate\Database\Eloquent\Collection<\Illuminate\Database\Eloquent\Model>
*
* @param \Illuminate\Database\Eloquent\Collection<int, \Illuminate\Database\Eloquent\Model> $results
* @param \Illuminate\Support\Collection<int, mixed> $values
* @param \Nuwave\Lighthouse\Bind\BindDefinition<\Illuminate\Database\Eloquent\Model> $definition
* @return \Illuminate\Database\Eloquent\Collection<string, \Illuminate\Database\Eloquent\Model>
*/
private function modelCollection(
EloquentCollection $results,
Expand Down
4 changes: 2 additions & 2 deletions src/Bind/Validation/BindingExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function setValidator(Validator $validator): self
}

/**
* @param callable(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
Expand All @@ -47,7 +47,7 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
continue;
}

$this->validator->addFailure("$attribute.$key", 'exists');
$this->validator?->addFailure("$attribute.$key", 'exists');
}
}
}
8 changes: 8 additions & 0 deletions tests/Utils/Bind/SpyCallableClassBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
final class SpyCallableClassBinding
{
private mixed $value = null;

/**
* @var \Nuwave\Lighthouse\Bind\BindDefinition<object>|null
*/
private ?BindDefinition $definition = null;

/**
Expand All @@ -21,6 +25,7 @@ public function __construct(
) {}

/**
* @param \Nuwave\Lighthouse\Bind\BindDefinition<object> $definition
* @return TReturn
*/
public function __invoke(mixed $value, BindDefinition $definition): mixed
Expand All @@ -31,6 +36,9 @@ public function __invoke(mixed $value, BindDefinition $definition): mixed
return $this->return;
}

/**
* @param \Nuwave\Lighthouse\Bind\BindDefinition<object> $definition
*/
public function assertCalledWith(mixed $value, BindDefinition $definition): void
{
Assert::assertSame($value, $this->value);
Expand Down
4 changes: 4 additions & 0 deletions tests/Utils/Resolvers/SpyResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
*/
final class SpyResolver
{
/**
* @var array<string, mixed>
*/
private array $args = [];

/**
Expand All @@ -19,6 +22,7 @@ public function __construct(
) {}

/**
* @param array<string, mixed> $args
* @return TReturn
*/
public function __invoke(mixed $root, array $args): mixed
Expand Down

0 comments on commit f0ddbeb

Please sign in to comment.