ViewResultCountDeriver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDerivativeDefinitions() 0 30 5
1
<?php
2
3
namespace Drupal\graphql_views\Plugin\Deriver\Fields;
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 ViewResultCountDeriver 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
        /** @var \Drupal\graphql_views\Plugin\views\display\GraphQL $display */
24
        $display = $this->getViewDisplay($view, $displayId);
25
        if (!$this->isPaged($display)) {
26
          continue;
27
        }
28
29
        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...
30
          continue;
31
        }
32
33
        $id = implode('-', [$viewId, $displayId, 'result', 'count']);
34
        $this->derivatives[$id] = [
35
          'id' => $id,
36
          'type' => 'Int',
37
          'parents' => [$display->getGraphQLResultName()],
38
          'view' => $viewId,
39
          'display' => $displayId,
40
        ] + $this->getCacheMetadataDefinition($view, $display) + $basePluginDefinition;
41
      }
42
    }
43
44
    return parent::getDerivativeDefinitions($basePluginDefinition);
45
  }
46
47
}
48