Skip to content

Commit 631ad00

Browse files
committed
Tighten up typing
1 parent fae6f12 commit 631ad00

16 files changed

+15
-70
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,11 @@ And to exclude a property from being exposed as a filter:
171171
use GraphQL\Doctrine\Annotation as API;
172172

173173
/**
174-
* @var string
175-
*
176174
* @API\Exclude
177175
*
178176
* @ORM\Column(type="string", length=255)
179177
*/
180-
private $password = '';
178+
private string $password = '';
181179
```
182180

183181
### Override output types
@@ -278,12 +276,10 @@ So usage would be like:
278276
use GraphQL\Doctrine\Annotation as API;
279277

280278
/**
281-
* @var string
282-
*
283279
* @API\FilterGroupCondition(type="?GraphQLTests\Doctrine\Blog\Types\PostStatusType")
284280
* @ORM\Column(type="string", options={"default" = Post::STATUS_PRIVATE})
285281
*/
286-
private $status = self::STATUS_PRIVATE;
282+
private string $status = self::STATUS_PRIVATE;
287283
```
288284

289285
An important thing to note is that the value of the type specified will be directly used in DQL. That means

src/Annotation/AbstractAnnotation.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ abstract class AbstractAnnotation
3030

3131
private ?string $description = null;
3232

33-
/**
34-
* @var mixed
35-
*/
36-
private $defaultValue;
33+
private mixed $defaultValue;
3734

3835
private bool $hasDefaultValue = false;
3936

@@ -95,18 +92,12 @@ public function hasDefaultValue(): bool
9592
return $this->hasDefaultValue;
9693
}
9794

98-
/**
99-
* @return mixed
100-
*/
101-
public function getDefaultValue()
95+
public function getDefaultValue(): mixed
10296
{
10397
return $this->defaultValue;
10498
}
10599

106-
/**
107-
* @param mixed $defaultValue
108-
*/
109-
public function setDefaultValue($defaultValue): void
100+
public function setDefaultValue(mixed $defaultValue): void
110101
{
111102
$this->defaultValue = $defaultValue;
112103
$this->hasDefaultValue = true;

src/DefaultFieldResolver.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717
final class DefaultFieldResolver
1818
{
1919
/**
20-
* @param mixed $source
2120
* @param mixed[] $args
22-
* @param mixed $context
23-
*
24-
* @return null|mixed
2521
*/
26-
public function __invoke($source, array $args, $context, ResolveInfo $info)
22+
public function __invoke(mixed $source, array $args, mixed $context, ResolveInfo $info): mixed
2723
{
28-
/** @var string $fieldName */
2924
$fieldName = $info->fieldName;
3025
$property = null;
3126

@@ -40,10 +35,8 @@ public function __invoke($source, array $args, $context, ResolveInfo $info)
4035

4136
/**
4237
* Resolve for an object.
43-
*
44-
* @return mixed
4538
*/
46-
private function resolveObject(object $source, array $args, string $fieldName)
39+
private function resolveObject(object $source, array $args, string $fieldName): mixed
4740
{
4841
$getter = $this->getGetter($source, $fieldName);
4942
if ($getter) {
@@ -61,10 +54,8 @@ private function resolveObject(object $source, array $args, string $fieldName)
6154

6255
/**
6356
* Resolve for an array.
64-
*
65-
* @return mixed
6657
*/
67-
private function resolveArray(array $source, string $fieldName)
58+
private function resolveArray(array $source, string $fieldName): mixed
6859
{
6960
return $source[$fieldName] ?? null;
7061
}

src/Definition/EntityID.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public function getId(): ?string
4545
*/
4646
public function getEntity(): object
4747
{
48-
/** @var null|T $entity */
4948
$entity = $this->entityManager->getRepository($this->className)->find($this->id);
5049
if (!$entity) {
5150
throw new Error('Entity not found for class `' . $this->className . '` and ID `' . $this->id . '`.');

src/Definition/EntityIDType.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,8 @@ public function serialize($value): string
4646

4747
/**
4848
* Parses an externally provided value (query variable) to use as an input.
49-
*
50-
* @param mixed $value
5149
*/
52-
public function parseValue($value, ?array $variables = null): EntityID
50+
public function parseValue(mixed $value, ?array $variables = null): EntityID
5351
{
5452
if (!is_string($value) && !is_int($value)) {
5553
throw new Error('EntityID cannot represent value: ' . \GraphQL\Utils\Utils::printSafe($value));

src/Definition/Operator/HaveOperatorType.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,8 @@ protected function getCollectionValuedDqlCondition(UniqueNameFactory $uniqueName
5151
if ($association['type'] === ClassMetadataInfo::ONE_TO_MANY) {
5252
$id = $metadata->identifier[0];
5353

54-
/** @var class-string $otherClassName */
5554
$otherClassName = $association['targetEntity'];
5655
$otherAlias = $uniqueNameFactory->createAliasName($otherClassName);
57-
/** @var string $otherField */
5856
$otherField = $association['mappedBy'];
5957
$otherMetadata = $queryBuilder->getEntityManager()->getClassMetadata($otherClassName);
6058
$otherId = $otherMetadata->identifier[0];

src/Factory/AbstractFieldsConfigurationFactory.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use ReflectionMethod;
1818
use ReflectionNamedType;
1919
use ReflectionParameter;
20-
use ReflectionProperty;
2120

2221
/**
2322
* A factory to create a configuration for all fields of an entity.
@@ -146,7 +145,6 @@ final protected function reflectionTypeToType(ReflectionNamedType $reflectionTyp
146145
private function findIdentityField(string $className): void
147146
{
148147
$this->metadata = $this->entityManager->getClassMetadata($className);
149-
/** @var array $meta */
150148
foreach ($this->metadata->fieldMappings as $meta) {
151149
if ($meta['id'] ?? false) {
152150
$this->identityField = $meta['fieldName'];
@@ -193,12 +191,9 @@ private function getTargetEntity(string $fieldName): ?string
193191
*
194192
* It does take into account that the property might be defined on a parent class
195193
* of entity. And it will find it if that is the case.
196-
*
197-
* @return mixed
198194
*/
199-
final protected function getPropertyDefaultValue(string $fieldName)
195+
final protected function getPropertyDefaultValue(string $fieldName): mixed
200196
{
201-
/** @var null|ReflectionProperty $property */
202197
$property = $this->metadata->getReflectionProperties()[$fieldName] ?? null;
203198
if (!$property) {
204199
return null;

src/Factory/FilteredQueryBuilderFactory.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace GraphQL\Doctrine\Factory;
66

77
use Doctrine\ORM\EntityManager;
8-
use Doctrine\ORM\EntityRepository;
98
use Doctrine\ORM\Mapping\ClassMetadata;
109
use Doctrine\ORM\QueryBuilder;
1110
use GraphQL\Doctrine\Definition\Operator\AbstractOperator;
@@ -48,7 +47,6 @@ public function create(string $className, array $filter, array $sorting): QueryB
4847
$this->dqlConditions = [];
4948
$this->uniqueJoins = [];
5049

51-
/** @var EntityRepository $repository */
5250
$repository = $this->entityManager->getRepository($className);
5351
$this->queryBuilder = $repository->createQueryBuilder($alias);
5452
$metadata = $this->entityManager->getClassMetadata($className);
@@ -129,7 +127,6 @@ private function applyJoins(ClassMetadata $metadata, array $joins, string $alias
129127
$joinedAlias = $this->createJoin($alias, $field, $join['type']);
130128

131129
if (isset($join['joins']) || isset($join['conditions'])) {
132-
/** @var class-string $targetClassName */
133130
$targetClassName = $metadata->getAssociationMapping($field)['targetEntity'];
134131
$targetMetadata = $this->entityManager->getClassMetadata($targetClassName);
135132
$type = $this->types->getFilterGroupCondition($targetClassName);

src/Factory/InputFieldsConfigurationFactory.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ protected function methodToConfiguration(ReflectionMethod $method): ?array
3333
$param = reset($params);
3434

3535
// Get a field from annotation, or an empty one
36-
/** @var Input $field */
3736
$field = $this->getAnnotationReader()->getMethodAnnotation($method, Input::class) ?? new Input();
3837

3938
if (!$field->getTypeInstance()) {

src/Factory/OutputFieldsConfigurationFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ protected function getMethodPattern(): string
2929
protected function methodToConfiguration(ReflectionMethod $method): ?array
3030
{
3131
// Get a field from annotation, or an empty one
32-
/** @var Field $field */
3332
$field = $this->getAnnotationReader()->getMethodAnnotation($method, Field::class) ?? new Field();
3433

3534
if (!$field->type instanceof Type) {
@@ -48,7 +47,6 @@ private function convertTypeDeclarationsToInstances(ReflectionMethod $method, Fi
4847
$field->type = $this->getTypeFromPhpDeclaration($method->getDeclaringClass(), $field->type);
4948
$args = [];
5049

51-
/** @var Argument $arg */
5250
foreach ($field->args as $arg) {
5351
$arg->setTypeInstance($this->getTypeFromPhpDeclaration($method->getDeclaringClass(), $arg->getType()));
5452
$args[$arg->getName()] = $arg;

0 commit comments

Comments
 (0)