Skip to content

Commit da07108

Browse files
Kingdutchspawnia
andcommitted
Improve interface extension related typehints
Co-authored-by: Benedikt Franke <[email protected]>
1 parent a8f94b6 commit da07108

File tree

6 files changed

+16
-18
lines changed

6 files changed

+16
-18
lines changed

src/Type/Definition/ImplementingType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface ImplementingType
1515
public function implementsInterface(InterfaceType $interfaceType) : bool;
1616

1717
/**
18-
* @return InterfaceType[]
18+
* @return array<int, InterfaceType>
1919
*/
2020
public function getInterfaces() : array;
2121
}

src/Type/Definition/InterfaceType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ class InterfaceType extends Type implements AbstractType, OutputType, CompositeT
3333
/**
3434
* Lazily initialized.
3535
*
36-
* @var InterfaceType[]
36+
* @var array<int, InterfaceType>
3737
*/
3838
private $interfaces;
3939

4040
/**
4141
* Lazily initialized.
4242
*
43-
* @var InterfaceType[]
43+
* @var array<string, InterfaceType>
4444
*/
4545
private $interfaceMap;
4646

@@ -131,7 +131,7 @@ public function implementsInterface(InterfaceType $interfaceType) : bool
131131
}
132132

133133
/**
134-
* @return InterfaceType[]
134+
* @return array<int, InterfaceType>
135135
*/
136136
public function getInterfaces() : array
137137
{

src/Type/Definition/ObjectType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ class ObjectType extends Type implements OutputType, CompositeType, NullableType
7676
/**
7777
* Lazily initialized.
7878
*
79-
* @var InterfaceType[]
79+
* @var array<int, InterfaceType>
8080
*/
8181
private $interfaces;
8282

8383
/**
8484
* Lazily initialized.
8585
*
86-
* @var InterfaceType[]
86+
* @var array<string, InterfaceType>
8787
*/
8888
private $interfaceMap;
8989

@@ -180,7 +180,7 @@ public function implementsInterface(InterfaceType $interfaceType) : bool
180180
}
181181

182182
/**
183-
* @return InterfaceType[]
183+
* @return array<int, InterfaceType>
184184
*/
185185
public function getInterfaces() : array
186186
{

src/Type/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ public function isPossibleType(AbstractType $abstractType, ObjectType $possibleT
497497
}
498498

499499
/**
500-
* Returns true if maybe sub type is a sub type of given abstract type.
500+
* Returns true if the given type is a sub type of the given abstract type.
501501
*
502502
* @param UnionType|InterfaceType $abstractType
503503
* @param ObjectType|InterfaceType $maybeSubType

src/Type/SchemaValidationContext.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ private function getFieldArgNode($type, $fieldName, $argName)
662662
/**
663663
* @param ObjectType|InterfaceType $type
664664
*/
665-
private function validateInterfaces(ImplementingType $type)
665+
private function validateInterfaces(ImplementingType $type) : void
666666
{
667667
$ifaceTypeNames = [];
668668
foreach ($type->getInterfaces() as $iface) {
@@ -717,11 +717,8 @@ private function getDirectives($object)
717717

718718
/**
719719
* @param ObjectType|InterfaceType $type
720-
* @param InterfaceType $iface
721-
*
722-
* @return NamedTypeNode|null
723720
*/
724-
private function getImplementsInterfaceNode($type, $iface)
721+
private function getImplementsInterfaceNode($type, Type $iface) : ?NamedTypeNode
725722
{
726723
$nodes = $this->getAllImplementsInterfaceNodes($type, $iface);
727724

@@ -894,9 +891,8 @@ private function validateTypeImplementsInterface($type, $iface)
894891

895892
/**
896893
* @param ObjectType|InterfaceType $type
897-
* @param InterfaceType $iface
898894
*/
899-
private function validateTypeImplementsAncestors(ImplementingType $type, $iface)
895+
private function validateTypeImplementsAncestors(ImplementingType $type, InterfaceType $iface) : void
900896
{
901897
$typeInterfaces = $type->getInterfaces();
902898
foreach ($iface->getInterfaces() as $transitive) {

src/Utils/ASTDefinitionBuilder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ private function makeTypeDef(ObjectTypeDefinitionNode $def)
278278
'fields' => function () use ($def) {
279279
return $this->makeFieldDefMap($def);
280280
},
281-
'interfaces' => function () use ($def) {
281+
'interfaces' => function () use ($def) : ?array {
282282
return $this->makeImplementedInterfaces($def);
283283
},
284284
'astNode' => $def,
@@ -331,8 +331,10 @@ private function getDeprecationReason($node)
331331

332332
/**
333333
* @param ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode $def
334+
*
335+
* @return array<int, InterfaceType> | null
334336
*/
335-
private function makeImplementedInterfaces($def)
337+
private function makeImplementedInterfaces($def) : ?array
336338
{
337339
if ($def->interfaces !== null) {
338340
// Note: While this could make early assertions to get the correctly
@@ -359,7 +361,7 @@ private function makeInterfaceDef(InterfaceTypeDefinitionNode $def)
359361
'fields' => function () use ($def) {
360362
return $this->makeFieldDefMap($def);
361363
},
362-
'interfaces' => function () use ($def) {
364+
'interfaces' => function () use ($def) : ?array {
363365
return $this->makeImplementedInterfaces($def);
364366
},
365367
'astNode' => $def,

0 commit comments

Comments
 (0)