Conditions | 12 |
Paths | 64 |
Total Lines | 79 |
Code Lines | 43 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
48 | public function getSchema(): Schema |
||
49 | { |
||
50 | $types = $this->typesFactory->getTypes(); |
||
51 | foreach ($types as $typeId => $type) { |
||
52 | $this->typesContainer->set($typeId, $type); |
||
53 | } |
||
54 | |||
55 | $queryFields = ['node' => $this->fieldsBuilder->getNodeQueryFields()]; |
||
56 | $mutationFields = []; |
||
57 | $subscriptionFields = []; |
||
58 | |||
59 | foreach ($this->resourceNameCollectionFactory->create() as $resourceClass) { |
||
60 | $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass); |
||
61 | /** @var array<string, mixed> $graphqlConfiguration */ |
||
62 | $graphqlConfiguration = $resourceMetadata->getGraphql() ?? []; |
||
63 | foreach ($graphqlConfiguration as $operationName => $value) { |
||
64 | if ('item_query' === $operationName) { |
||
65 | $queryFields += $this->fieldsBuilder->getItemQueryFields($resourceClass, $resourceMetadata, $operationName, []); |
||
66 | |||
67 | continue; |
||
68 | } |
||
69 | |||
70 | if ('collection_query' === $operationName) { |
||
71 | $queryFields += $this->fieldsBuilder->getCollectionQueryFields($resourceClass, $resourceMetadata, $operationName, []); |
||
72 | |||
73 | continue; |
||
74 | } |
||
75 | |||
76 | if ($resourceMetadata->getGraphqlAttribute($operationName, 'item_query')) { |
||
77 | $queryFields += $this->fieldsBuilder->getItemQueryFields($resourceClass, $resourceMetadata, $operationName, $value); |
||
78 | |||
79 | continue; |
||
80 | } |
||
81 | |||
82 | if ($resourceMetadata->getGraphqlAttribute($operationName, 'collection_query')) { |
||
83 | $queryFields += $this->fieldsBuilder->getCollectionQueryFields($resourceClass, $resourceMetadata, $operationName, $value); |
||
84 | |||
85 | continue; |
||
86 | } |
||
87 | |||
88 | if ('update' === $operationName) { |
||
89 | $subscriptionFields += $this->fieldsBuilder->getSubscriptionFields($resourceClass, $resourceMetadata, $operationName); |
||
90 | } |
||
91 | |||
92 | $mutationFields += $this->fieldsBuilder->getMutationFields($resourceClass, $resourceMetadata, $operationName); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | $schema = [ |
||
97 | 'query' => new ObjectType([ |
||
98 | 'name' => 'Query', |
||
99 | 'fields' => $queryFields, |
||
100 | ]), |
||
101 | 'typeLoader' => function ($name) { |
||
102 | $type = $this->typesContainer->get($name); |
||
103 | |||
104 | if ($type instanceof WrappingType) { |
||
105 | return $type->getWrappedType(true); |
||
106 | } |
||
107 | |||
108 | return $type; |
||
109 | }, |
||
110 | ]; |
||
111 | |||
112 | if ($mutationFields) { |
||
113 | $schema['mutation'] = new ObjectType([ |
||
114 | 'name' => 'Mutation', |
||
115 | 'fields' => $mutationFields, |
||
116 | ]); |
||
117 | } |
||
118 | |||
119 | if ($subscriptionFields) { |
||
120 | $schema['subscription'] = new ObjectType([ |
||
121 | 'name' => 'Subscription', |
||
122 | 'fields' => $subscriptionFields, |
||
123 | ]); |
||
124 | } |
||
125 | |||
126 | return new Schema($schema); |
||
127 | } |
||
129 |