ViewResultTypeDeriver::getDerivativeDefinitions()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 4
nc 2
nop 1
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 fields from configured views.
10
 */
11
class ViewResultTypeDeriver 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
        /** @var \Drupal\graphql_views\Plugin\views\display\GraphQL $display */
28
        $display = $this->getViewDisplay($view, $displayId);
29
30
        $id = implode('-', [$viewId, $displayId, 'result']);
31
        $this->derivatives[$id] = [
32
          'id' => $id,
33
          'name' => $display->getGraphQLResultName(),
34
          'view' => $viewId,
35
          'display' => $displayId,
36
        ] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
37
      }
38
    }
39
40
    return parent::getDerivativeDefinitions($basePluginDefinition);
41
  }
42
43
}
44