Conditions | 11 |
Paths | 37 |
Total Lines | 40 |
Code Lines | 21 |
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 |
||
68 | public function processQuery($schemaId, $query, array $variables = [], $bypassSecurity = FALSE) { |
||
69 | if (!$schema = $this->schemaLoader->getSchema($schemaId)) { |
||
70 | throw new \InvalidArgumentException(sprintf('Could not load schema %s', [$schemaId])); |
||
71 | } |
||
72 | |||
73 | // Set up the processor with parameters to be used in the resolvers. |
||
74 | $processor = new Processor($schema); |
||
75 | $context = $processor->getExecutionContext(); |
||
76 | $container = $context->getContainer(); |
||
77 | $secure = !!($bypassSecurity || $this->currentUser->hasPermission('bypass graphql field security') || $this->parameters['development']); |
||
78 | $container->set('secure', $secure); |
||
79 | $container->set('metadata', new CacheableMetadata()); |
||
80 | |||
81 | // Run the query against the parser. |
||
82 | $result = $processor->processPayload($query, $variables)->getResponseData(); |
||
83 | |||
84 | // Add collected cache metadata from the query processor. |
||
85 | $responseCacheMetadata = new CacheableMetadata(); |
||
86 | if ($container->has('metadata') && ($metadata = $container->get('metadata'))) { |
||
87 | if ($metadata instanceof CacheableDependencyInterface) { |
||
|
|||
88 | $responseCacheMetadata->addCacheableDependency($metadata); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | // Prevent caching if this is a mutation query or an error occurred. |
||
93 | $request = $context->getRequest(); |
||
94 | if ((!empty($request) && $request->hasMutations()) || $context->hasErrors()) { |
||
95 | $responseCacheMetadata->setCacheMaxAge(0); |
||
96 | } |
||
97 | |||
98 | // Do not cache this response anywhere (even page cache) if the graphql |
||
99 | // cache is disabled through the service parameters. |
||
100 | if (empty($config['result_cache'])) { |
||
101 | $responseCacheMetadata->setCacheMaxAge(0); |
||
102 | } |
||
103 | |||
104 | // Load the schema's cache metadata. |
||
105 | $schemaCacheMetadata = $this->schemaLoader->getResponseCacheMetadata($schemaId); |
||
106 | return new QueryResult($result, $responseCacheMetadata, $schemaCacheMetadata); |
||
107 | } |
||
108 | |||
110 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.