Skip to content

Commit 9d0babb

Browse files
committed
tests, linting, stanning
1 parent 5c93da5 commit 9d0babb

10 files changed

+413
-28
lines changed

src/Type/Definition/FieldDefinition.php

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public static function defineFieldMap(Type $type, $fields)
9696
}
9797
$map = [];
9898
foreach ($fields as $name => $field) {
99+
$field = Type::resolveLazyType($field);
99100
if (is_array($field)) {
100101
if (! isset($field['name'])) {
101102
if (! is_string($name)) {

src/Type/Definition/ListOfType.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44

55
namespace GraphQL\Type\Definition;
66

7+
use function is_callable;
8+
79
class ListOfType extends Type implements WrappingType, OutputType, NullableType, InputType
810
{
911
/** @var ObjectType|InterfaceType|UnionType|ScalarType|InputObjectType|EnumType */
10-
private $_ofType;
12+
private $ofType;
1113

1214
/**
1315
* @param callable|Type $type
1416
*/
1517
public function __construct($type)
1618
{
17-
$this->_ofType = is_callable($type) ? $type : Type::assertType($type);
19+
$this->ofType = is_callable($type) ? $type : Type::assertType($type);
1820
}
1921

2022
public function toString() : string
2123
{
22-
return '[' . $this->ofType->toString() . ']';
24+
return '[' . $this->getOfType()->toString() . ']';
2325
}
2426

25-
public function __get($name)
27+
public function getOfType()
2628
{
27-
switch ($name) {
28-
case "ofType":
29-
return Type::resolveLazyType($this->_ofType);
30-
}
29+
return Type::resolveLazyType($this->ofType);
3130
}
3231

3332
/**
@@ -37,7 +36,7 @@ public function __get($name)
3736
*/
3837
public function getWrappedType($recurse = false)
3938
{
40-
$type = $this->ofType;
39+
$type = $this->getOfType();
4140

4241
return $recurse && $type instanceof WrappingType
4342
? $type->getWrappedType($recurse)

src/Type/Definition/NonNull.php

+9-11
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,19 @@
55
namespace GraphQL\Type\Definition;
66

77
use GraphQL\Utils\Utils;
8+
use function is_callable;
89

910
class NonNull extends Type implements WrappingType, OutputType, InputType
1011
{
1112
/** @var NullableType */
12-
private $_ofType;
13+
private $ofType;
1314

1415
/**
1516
* @param NullableType $type
1617
*/
1718
public function __construct($type)
1819
{
19-
$this->_ofType = is_callable($type) ? $type : self::assertNullableType($type);
20-
}
21-
22-
public function __get($name)
23-
{
24-
switch ($name) {
25-
case "ofType":
26-
return Type::resolveLazyType($this->_ofType);
27-
}
20+
$this->ofType = is_callable($type) ? $type : self::assertNullableType($type);
2821
}
2922

3023
/**
@@ -65,14 +58,19 @@ public function toString()
6558
return $this->getWrappedType()->toString() . '!';
6659
}
6760

61+
public function getOfType()
62+
{
63+
return Type::resolveLazyType($this->ofType);
64+
}
65+
6866
/**
6967
* @param bool $recurse
7068
*
7169
* @return Type
7270
*/
7371
public function getWrappedType($recurse = false)
7472
{
75-
$type = $this->ofType;
73+
$type = $this->getOfType();
7674

7775
return $recurse && $type instanceof WrappingType
7876
? $type->getWrappedType($recurse)

src/Type/Definition/ObjectType.php

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ private function getInterfaceMap()
171171
if ($this->interfaceMap === null) {
172172
$this->interfaceMap = [];
173173
foreach ($this->getInterfaces() as $interface) {
174+
$interface = Type::resolveLazyType($interface);
174175
$this->interfaceMap[$interface->name] = $interface;
175176
}
176177
}

src/Type/Definition/Type.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use function array_merge;
1818
use function implode;
1919
use function in_array;
20+
use function is_callable;
2021
use function preg_replace;
2122
use function trigger_error;
2223
use const E_USER_DEPRECATED;
@@ -315,7 +316,7 @@ public static function isAbstractType($type) : bool
315316
public static function assertType($type)
316317
{
317318
$isType = self::isType($type);
318-
if(!$isType) {
319+
if (! $isType) {
319320
Utils::invariant(
320321
$isType,
321322
'Expected ' . Utils::printSafe($type) . ' to be a GraphQL type.'
@@ -326,7 +327,7 @@ public static function assertType($type)
326327
}
327328

328329
/**
329-
* @param callable|Type
330+
* @param callable|Type $type
330331
*
331332
* @return mixed
332333
*/

src/Type/Definition/UnionType.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GraphQL\Language\AST\UnionTypeDefinitionNode;
99
use GraphQL\Language\AST\UnionTypeExtensionNode;
1010
use GraphQL\Utils\Utils;
11+
use function array_map;
1112
use function call_user_func;
1213
use function is_array;
1314
use function is_callable;
@@ -57,8 +58,7 @@ public function isPossibleType(Type $type) : bool
5758
if ($this->possibleTypeNames === null) {
5859
$this->possibleTypeNames = [];
5960
foreach ($this->getTypes() as $possibleType) {
60-
$possibleType = Type::resolveLazyType($possibleType);
61-
$this->possibleTypeNames[$possibleType->name] = true;
61+
$this->possibleTypeNames[Type::resolveLazyType($possibleType)->name] = true;
6262
}
6363
}
6464

@@ -88,7 +88,9 @@ public function getTypes()
8888
);
8989
}
9090

91-
$this->types = $types;
91+
$this->types = array_map(static function ($type) {
92+
return Type::resolveLazyType($type);
93+
}, $types);
9294
}
9395

9496
return $this->types;

src/Type/Schema.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ private function resolveAdditionalTypes()
172172
}
173173

174174
foreach ($types as $index => $type) {
175+
$type = Type::resolveLazyType($type);
175176
if (! $type instanceof Type) {
176177
throw new InvariantViolation(sprintf(
177178
'Each entry of schema types must be instance of GraphQL\Type\Definition\Type but entry at %s is %s',
@@ -379,7 +380,7 @@ private function loadType($typeName)
379380
*/
380381
private function defaultTypeLoader($typeName)
381382
{
382-
// Default type loader simply fallbacks to collecting all types
383+
// Default type loader simply falls back to collecting all types
383384
$typeMap = $this->getTypeMap();
384385

385386
return $typeMap[$typeName] ?? null;
@@ -424,7 +425,6 @@ private function getPossibleTypeMap()
424425
}
425426
} elseif ($type instanceof UnionType) {
426427
foreach ($type->getTypes() as $innerType) {
427-
$innerType = Type::resolveLazyType($innerType);
428428
$this->possibleTypeMap[$type->name][$innerType->name] = $innerType;
429429
}
430430
}

src/Utils/SchemaExtender.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ protected static function extendImplementedInterfaces(ObjectType $type) : array
296296
protected static function extendType($typeDef)
297297
{
298298
if ($typeDef instanceof ListOfType) {
299-
return Type::listOf(static::extendType($typeDef->ofType));
299+
return Type::listOf(static::extendType($typeDef->getOfType()));
300300
}
301301

302302
if ($typeDef instanceof NonNull) {

0 commit comments

Comments
 (0)