ViewRowTypeDeriver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDerivativeDefinitions() 0 32 5
1
<?php
2
3
namespace Drupal\graphql_views\Plugin\Deriver\Types;
4
5
use Drupal\graphql_views\Plugin\Deriver\ViewDeriverBase;
6
use Drupal\views\Views;
7
8
/**
9
 * Derive row types from configured fieldable views.
10
 */
11
class ViewRowTypeDeriver extends ViewDeriverBase {
12
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public function getDerivativeDefinitions($basePluginDefinition) {
17
    if ($this->entityTypeManager->hasDefinition('view')) {
18
      $viewStorage = $this->entityTypeManager->getStorage('view');
19
20
      foreach (Views::getApplicableViews('graphql_display') as list($viewId, $displayId)) {
21
        /** @var \Drupal\views\ViewEntityInterface $view */
22
        $view = $viewStorage->load($viewId);
23
        if (!$this->getRowResolveType($view, $displayId)) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->getRowResolveType($view, $displayId) of type null|string is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
24
          continue;
25
        }
26
27
        $style = $this->getViewStyle($view, $displayId);
28
        // This deriver only supports style plugins that use fields.
29
        if (!$style->usesFields()) {
30
          continue;
31
        }
32
33
        /** @var \Drupal\graphql_views\Plugin\views\display\GraphQL $display */
34
        $display = $this->getViewDisplay($view, $displayId);
35
36
        $id = implode('-', [$viewId, $displayId, 'row']);
37
        $this->derivatives[$id] = [
38
          'id' => $id,
39
          'name' => $display->getGraphQLRowName(),
40
          'view' => $viewId,
41
          'display' => $displayId,
42
        ] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
43
      }
44
    }
45
46
    return parent::getDerivativeDefinitions($basePluginDefinition);
47
  }
48
49
}
50