| Conditions | 15 |
| Paths | 2 |
| Total Lines | 65 |
| 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 |
||
| 43 | public function getDerivativeDefinitions($basePluginDefinition) { |
||
| 44 | if ($this->entityTypeManager->hasDefinition('view')) { |
||
| 45 | $viewStorage = $this->entityTypeManager->getStorage('view'); |
||
| 46 | |||
| 47 | foreach (Views::getApplicableViews('graphql_display') as [$viewId, $displayId]) { |
||
| 48 | /** @var \Drupal\views\ViewEntityInterface $view */ |
||
| 49 | $view = $viewStorage->load($viewId); |
||
|
|
|||
| 50 | if (!$this->getRowResolveType($view, $displayId)) { |
||
| 51 | continue; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** @var \Drupal\graphql_views\Plugin\views\display\GraphQL $display */ |
||
| 55 | $display = $this->getViewDisplay($view, $displayId); |
||
| 56 | $arg_options = $display->getOption('arguments'); |
||
| 57 | |||
| 58 | if (count($arg_options) == 1) { |
||
| 59 | $arg_option = reset($arg_options); |
||
| 60 | |||
| 61 | if (!empty($arg_option['validate']['type']) && strpos($arg_option['validate']['type'], ':') !== FALSE) { |
||
| 62 | [$type, $entityTypeId] = explode(':', $arg_option['validate']['type']); |
||
| 63 | if ($type == 'entity' && isset($entityTypeId)) { |
||
| 64 | $entityType = $this->entityTypeManager->getDefinition($entityTypeId); |
||
| 65 | $supportsBundles = $entityType->hasKey('bundle'); |
||
| 66 | $bundles = $supportsBundles && isset($arg_option['validate_options']['bundles']) ? array_values($arg_option['validate_options']['bundles']) : []; |
||
| 67 | $id = implode('-', [$viewId, $displayId, 'sub-view']); |
||
| 68 | $arguments = []; |
||
| 69 | $arguments += $this->getPagerArguments($display); |
||
| 70 | $arguments += $this->getSortArguments($display, $id); |
||
| 71 | $arguments += $this->getFilterArguments($display, $id); |
||
| 72 | |||
| 73 | $parents = []; |
||
| 74 | if (empty($bundles)) { |
||
| 75 | $parents[] = StringHelper::camelCase($entityTypeId); |
||
| 76 | |||
| 77 | if ($supportsBundles) { |
||
| 78 | $bundleInfo = array_keys($this->entityTypeBundleInfo->getBundleInfo($entityTypeId)); |
||
| 79 | foreach ($bundleInfo as $bundle) { |
||
| 80 | $parents[] = StringHelper::camelCase($entityTypeId, $bundle); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | } |
||
| 84 | else { |
||
| 85 | foreach ($bundles as $bundle) { |
||
| 86 | $parents[] = StringHelper::camelCase($entityTypeId, $bundle); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->derivatives[$id] = [ |
||
| 91 | 'id' => $id, |
||
| 92 | 'name' => $display->getGraphQLQueryName(), |
||
| 93 | 'type' => $display->getGraphQLResultName(), |
||
| 94 | 'parents' => $parents, |
||
| 95 | 'arguments' => $arguments, |
||
| 96 | 'view' => $viewId, |
||
| 97 | 'display' => $displayId, |
||
| 98 | 'paged' => $this->isPaged($display), |
||
| 99 | ] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition; |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | return parent::getDerivativeDefinitions($basePluginDefinition); |
||
| 107 | } |
||
| 108 | |||
| 110 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.