| Conditions | 7 |
| Paths | 2 |
| Total Lines | 70 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 21 | public function __construct(QueryProviderInterface $queryProvider, RecursiveTypeMapperInterface $recursiveTypeMapper, TypeResolver $typeResolver, SchemaConfig $config = null) |
||
| 22 | { |
||
| 23 | if ($config === null) { |
||
| 24 | $config = SchemaConfig::create(); |
||
| 25 | } |
||
| 26 | |||
| 27 | $query = new ObjectType([ |
||
| 28 | 'name' => 'Query', |
||
| 29 | 'fields' => function() use ($queryProvider) { |
||
| 30 | $queries = $queryProvider->getQueries(); |
||
| 31 | if (empty($queries)) { |
||
| 32 | return [ |
||
| 33 | 'dummyQuery' => [ |
||
| 34 | 'type' => Type::string(), |
||
| 35 | 'description' => 'A placeholder query used by thecodingmachine/graphql-controllers when there are no declared queries.', |
||
| 36 | 'resolve' => function () { |
||
| 37 | return 'This is a placeholder query. Please create a query using the @Query annotation.'; |
||
| 38 | } |
||
| 39 | ] |
||
| 40 | ]; |
||
| 41 | } |
||
| 42 | return $queryProvider->getQueries(); |
||
| 43 | } |
||
| 44 | ]); |
||
| 45 | $mutation = new ObjectType([ |
||
| 46 | 'name' => 'Mutation', |
||
| 47 | 'fields' => function() use ($queryProvider) { |
||
| 48 | $mutations = $queryProvider->getMutations(); |
||
| 49 | if (empty($mutations)) { |
||
| 50 | return [ |
||
| 51 | 'dummyMutation' => [ |
||
| 52 | 'type' => Type::string(), |
||
| 53 | 'description' => 'A placeholder query used by thecodingmachine/graphql-controllers when there are no declared mutations.', |
||
| 54 | 'resolve' => function () { |
||
| 55 | return 'This is a placeholder mutation. Please create a mutation using the @Mutation annotation.'; |
||
| 56 | } |
||
| 57 | ] |
||
| 58 | ]; |
||
| 59 | } |
||
| 60 | return $mutations; |
||
| 61 | } |
||
| 62 | ]); |
||
| 63 | |||
| 64 | $config->setQuery($query); |
||
| 65 | $config->setMutation($mutation); |
||
| 66 | |||
| 67 | $config->setTypes(function() use ($recursiveTypeMapper) { |
||
| 68 | return $recursiveTypeMapper->getOutputTypes(); |
||
| 69 | }); |
||
| 70 | |||
| 71 | $config->setTypeLoader(function(string $name) use ($recursiveTypeMapper, $query, $mutation) { |
||
| 72 | // We need to find a type FROM a GraphQL type name |
||
| 73 | if ($name === 'Query') { |
||
| 74 | return $query; |
||
| 75 | } |
||
| 76 | if ($name === 'Mutation') { |
||
| 77 | return $mutation; |
||
| 78 | } |
||
| 79 | |||
| 80 | $type = CustomTypesRegistry::mapNameToType($name); |
||
| 81 | if ($type !== null) { |
||
| 82 | return $type; |
||
| 83 | } |
||
| 84 | |||
| 85 | return $recursiveTypeMapper->mapNameToType($name); |
||
| 86 | }); |
||
| 87 | |||
| 88 | $typeResolver->registerSchema($this); |
||
| 89 | |||
| 90 | parent::__construct($config); |
||
| 91 | } |
||
| 93 |