Conditions | 8 |
Paths | 10 |
Total Lines | 53 |
Lines | 53 |
Ratio | 100 % |
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 |
||
63 | public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
||
64 | $storage = $this->entityTypeManager->getStorage('view'); |
||
65 | $definition = $this->getPluginDefinition(); |
||
66 | |||
67 | /** @var \Drupal\views\Entity\View $view */ |
||
68 | if ($view = $storage->load($definition['view'])) { |
||
69 | $executable = $view->getExecutable(); |
||
70 | $executable->setDisplay($definition['display']); |
||
71 | /** @var \Drupal\graphql_views\Plugin\views\display\GraphQL $display */ |
||
72 | $display = $executable->getDisplay($definition['display']); |
||
73 | |||
74 | // a subview can only work on an entity, so return null it it is not. |
||
75 | |||
76 | if (!$value instanceof EntityInterface) { |
||
77 | return; |
||
78 | } |
||
79 | |||
80 | // Set the first argument to the id of the current entity. |
||
81 | $executable->setArguments([$value->id()]); |
||
82 | |||
83 | $filters = $executable->getDisplay()->getOption('filters');; |
||
84 | $input = $this->extractExposedInput($value, $args, $filters); |
||
85 | $executable->setExposedInput($input); |
||
86 | |||
87 | // This is a workaround for the Taxonomy Term filter which requires a full |
||
88 | // exposed form to be sent OR the display being an attachment to just |
||
89 | // accept input values. |
||
90 | $executable->is_attachment = TRUE; |
||
91 | $executable->exposed_raw_input = $input; |
||
92 | |||
93 | if (!empty($definition['paged'])) { |
||
94 | // Set paging parameters. |
||
95 | $executable->setItemsPerPage($args['pageSize']); |
||
96 | $executable->setCurrentPage($args['page']); |
||
97 | } |
||
98 | |||
99 | if (isset($args['offset']) && !empty($args['offset'])) { |
||
100 | $executable->setOffset($args['offset']); |
||
101 | } |
||
102 | |||
103 | $result = $executable->render($definition['display']); |
||
104 | /** @var \Drupal\Core\Cache\CacheableMetadata $cache */ |
||
105 | if ($cache = $result['cache']) { |
||
106 | $cache->setCacheContexts( |
||
107 | array_filter($cache->getCacheContexts(), function ($context) { |
||
108 | // Don't emit the url cache contexts. |
||
109 | return $context !== 'url' && strpos($context, 'url.') !== 0; |
||
110 | }) |
||
111 | ); |
||
112 | } |
||
113 | yield $result; |
||
114 | } |
||
115 | } |
||
116 | |||
202 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.