Passed
Pull Request — 8.x-1.x (#18)
by Frédéric G.
05:46
created

Overrides   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 33
dl 0
loc 54
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A run() 0 21 3
A checkViewType() 0 20 5
1
<?php
2
3
namespace Drupal\qa\Plugin\Qa\Control\Views;
4
5
class Overrides extends Views {
6
7
  /**
8
   * {@inheritdoc]
9
   */
10
  public function init() {
11
    $this->package_name = __NAMESPACE__;
12
    $this->title = t('Non-default views');
13
    $this->description = t('Have any views been overridden or only created in the DB ? This is a performance and change management issue.');
14
  }
15
16
  function checkViewType($view) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
17
    $status = $view->type == t('Default') ? 1 : 0;
18
    if (!$status) {
19
      $name = empty($view->human_name) ? $view->name : $view->human_name;
20
      $result = [
21
          module_exists('views_ui')
0 ignored issues
show
Bug introduced by
The function module_exists was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

21
          /** @scrutinizer ignore-call */ 
22
          module_exists('views_ui')
Loading history...
22
          ? l($name, "admin/structure/views/view/{$view->name}/edit")
0 ignored issues
show
Bug introduced by
The function l was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
          ? /** @scrutinizer ignore-call */ l($name, "admin/structure/views/view/{$view->name}/edit")
Loading history...
23
          : $name,
24
          $view->type
25
      ];
26
    }
27
    else {
28
      $result = NULL;
29
    }
30
    $ret = [
31
      'name'   => $view->name,
32
      'status' => $status,
33
      'result' => $result,
34
    ];
35
    return $ret;
36
  }
37
38
  function run() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
    $pass = parent::run();
40
    $views = views_get_all_views(TRUE);
0 ignored issues
show
Bug introduced by
The function views_get_all_views was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
    $views = /** @scrutinizer ignore-call */ views_get_all_views(TRUE);
Loading history...
41
    foreach ($views as $view) {
42
      $pass->record($this->checkViewType($view));
43
    }
44
    $pass->life->end();
45
46
    // Prepare for theming
47
    $result = [];
48
    // @XXX May be inconsistent with non-BMP strings ?
49
    uksort($pass->result, 'strcasecmp');
50
    foreach ($pass->result as $view_report) {
51
      $result[] = t('!view: @type', [
52
        '!view' => $view_report[0], // Built safe in self::checkViewPhp
53
        '@type' => $view_report[1],
54
      ]);
55
    }
56
    $result = theme('item_list', ['items' => $result]);
0 ignored issues
show
Bug introduced by
The function theme was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
    $result = /** @scrutinizer ignore-call */ theme('item_list', ['items' => $result]);
Loading history...
57
    $pass->result = $result;
58
    return $pass;
59
  }
60
}
61