Passed
Pull Request — 8.x-1.x (#5)
by Frédéric G.
01:37
created

ProjectsReportController   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 167
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 81
dl 0
loc 167
rs 10
c 0
b 0
f 0
wmc 15

6 Methods

Rating   Name   Duplication   Size   Complexity  
B qa_report_projects() 0 67 9
A action() 0 3 1
A qa_report_project() 0 13 1
A buildProjects() 0 23 2
A __construct() 0 6 1
A create() 0 4 1
1
<?php
2
3
/**
4
 * This file was previously qa_projects.inc.
5
 */
6
7
namespace Drupal\qa\Controller;
8
9
use Drupal\Core\Controller\ControllerBase;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\Controller\ControllerBase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Drupal\Core\KeyValueStore\KeyValueExpirableFactory;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\KeyValueStore\KeyValueExpirableFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\KeyValueStor...pirableFactoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\KeyValueStor...StoreExpirableInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Drupal\Core\KeyValueStore\KeyValueStoreInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\Core\KeyValueStore\KeyValueStoreInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Drupal\qa\System\Module;
15
use Drupal\update\UpdateManagerInterface;
0 ignored issues
show
Bug introduced by
The type Drupal\update\UpdateManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Symfony\Component\DependencyInjection\ContainerInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Depend...tion\ContainerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * Class ProjectsReportController.
20
 *
21
 * @package Drupal\qa\Controller
22
 */
23
class ProjectsReportController extends ControllerBase {
24
25
  /**
26
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
27
   */
28
  protected $keyValueExpirable;
29
30
  /**
31
   * @var \Drupal\update\UpdateManagerInterface
32
   */
33
  protected $updateManager;
34
35
  public function __construct(
36
    UpdateManagerInterface $updateManager,
37
    KeyValueExpirableFactoryInterface $kveFactory
38
  ) {
39
    $this->keyValueExpirable = $kveFactory->get('update');
40
    $this->updateManager = $updateManager;
41
  }
42
43
  public static function create(ContainerInterface $container) {
44
    $updateManager = $container->get('update.manager');
45
    $kve = $container->get('keyvalue.expirable');
46
    return new static($updateManager, $kve);
47
  }
48
49
  /**
50
   * Action.
51
   *
52
   * @return string
53
   *   Return Hello string.
54
   */
55
  public function action() {
56
    $projects = $this->buildProjects(1);
0 ignored issues
show
Unused Code introduced by
The call to Drupal\qa\Controller\Pro...roller::buildProjects() has too many arguments starting with 1. ( Ignorable by Annotation )

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

56
    /** @scrutinizer ignore-call */ 
57
    $projects = $this->buildProjects(1);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
57
    return $projects;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $projects returns the type array<string,array|string> which is incompatible with the documented return type string.
Loading history...
58
  }
59
60
  /**
61
   * Build the list of projects.
62
   *
63
   * On most sites, this will just hold "drupal" and "OSInet QA", since most
64
   * code does not use the undocumented project info file key.
65
   *
66
   * @return array
67
   *   A render array.
68
   */
69
  protected function buildProjects() {
70
    $this->keyValueExpirable->delete('update_project_projects');
71
    $projects = $this->updateManager->getProjects();
72
    $build = [
73
      '#type' => 'table',
74
      '#header' => [
75
        $this->t('Name'),
76
        $this->t('Type'),
77
        $this->t('Status'),
78
      ],
79
      '#rows' => [],
80
    ];
81
82
    foreach ($projects as $projectName => $project) {
83
      $row = [
84
        $projectName,
85
        $project['project_type'],
86
        $project['project_status'],
87
      ];
88
      $build['#rows'][] = $row;
89
    }
90
91
    return $build;
92
  }
93
94
  /**
95
   * @param \Drupal\qa\Controller\Variable|NULL $variable
96
   *
97
   * @return string
98
   *
99
   * FIXME this is is legacy D7 one-off code.
100
   */
101
  function qa_report_project(Variable $variable = NULL) {
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...
102
    $c = cache_get('views_data:fr', 'cache_views');
0 ignored issues
show
Bug introduced by
The function cache_get 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

102
    $c = /** @scrutinizer ignore-call */ cache_get('views_data:fr', 'cache_views');
Loading history...
103
    $ret = '<pre>' . json_encode($c, JSON_PRETTY_PRINT) . '</pre>';
104
    return $ret;
105
    $bc = drupal_get_breadcrumb();
0 ignored issues
show
Unused Code introduced by
$bc = drupal_get_breadcrumb() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
Bug introduced by
The function drupal_get_breadcrumb 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

105
    $bc = /** @scrutinizer ignore-call */ drupal_get_breadcrumb();
Loading history...
106
    $bc[] = l(t('Administration'), 'admin');
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

106
    $bc[] = /** @scrutinizer ignore-call */ l(t('Administration'), 'admin');
Loading history...
Bug introduced by
The function t 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

106
    $bc[] = l(/** @scrutinizer ignore-call */ t('Administration'), 'admin');
Loading history...
107
    $bc[] = l(t('Reports'), 'admin/reports');
108
    $bc[] = l(t('Quality Assurance'), 'admin/reports/qa');
109
    $bc[] = l(t('Variables'), 'admin/reports/qa/variable');
110
    drupal_set_breadcrumb($bc);
0 ignored issues
show
Bug introduced by
The function drupal_set_breadcrumb 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

110
    /** @scrutinizer ignore-call */ 
111
    drupal_set_breadcrumb($bc);
Loading history...
111
112
    drupal_set_title(t('Variable: %name', array('%name' => $variable->name)), PASS_THROUGH);
0 ignored issues
show
Bug introduced by
The constant Drupal\qa\Controller\PASS_THROUGH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function drupal_set_title 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

112
    /** @scrutinizer ignore-call */ 
113
    drupal_set_title(t('Variable: %name', array('%name' => $variable->name)), PASS_THROUGH);
Loading history...
113
    return $variable->dump();
114
  }
115
116
  /**
117
   * Page callback for projects list.
118
   *
119
   * @return string
120
   *
121
   * @FIXME This still uses the D7 info structure.
122
   */
123
  function qa_report_projects() {
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...
124
    $ret = '<h3>Projects</h3>';
125
    drupal_static_reset('update_get_projects');
0 ignored issues
show
Bug introduced by
The function drupal_static_reset 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

125
    /** @scrutinizer ignore-call */ 
126
    drupal_static_reset('update_get_projects');
Loading history...
126
    $GLOBALS['conf']['update_check_disabled'] = TRUE;
127
    $projects = update_get_projects();
0 ignored issues
show
Bug introduced by
The function update_get_projects 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

127
    $projects = /** @scrutinizer ignore-call */ update_get_projects();
Loading history...
128
    ksort($projects);
129
    $ret .= kprint_r($projects, TRUE);
0 ignored issues
show
Bug introduced by
The function kprint_r 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

129
    $ret .= /** @scrutinizer ignore-call */ kprint_r($projects, TRUE);
Loading history...
130
131
    $ret .= '<h3>Modules info</h3>';
132
    list($modules, $projects) = Module::getInfo();
133
134
    $header = array(
135
      t('Project'),
0 ignored issues
show
Bug introduced by
The function t 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

135
      /** @scrutinizer ignore-call */ 
136
      t('Project'),
Loading history...
136
      t('Module'),
137
      t('Module status'),
138
      t('Project status'),
139
    );
140
141
    $rows = array();
142
    $previous_project = '';
143
    /** @var \Drupal\qa\System\Project $project */
144
    foreach ($projects as $name => $project) {
145
      $row = array();
146
      $project_cell = array(
147
        'data' => $name,
148
      );
149
      $count = $project->useCount();
150
      if ($count > 1) {
151
        //$project_cell['rowspan'] = $count;
152
      }
153
      if ($name != $previous_project) {
154
        $previous_project = $name;
155
      }
156
157
      $enabled = t('Enabled');
158
      $disabled = t('Disabled');
159
160
      /** @var \Drupal\qa\System\Module $module */
161
      foreach (array_values($project->modules) as $index => $module) {
162
        $row = array();
163
        $row[] = ($index === 0) ? $project_cell : '';
164
165
        $row[] = $module->name;
166
        $row[] = $module->isEnabled() ? $enabled : $disabled;
167
168
        if ($index === 0) {
169
          if ($count === 0) {
170
            $last_cell = array(
171
              'style' => 'background-color: #ff8080',
172
              'data' => $count,
173
            );
174
          }
175
          else {
176
            $last_cell = $count;
177
          }
178
        }
179
        else {
180
          $last_cell = '';
181
        }
182
        $row[] = $last_cell;
183
184
        $rows[] = $row;
185
      }
186
    }
187
    return theme('table', array(
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

187
    return /** @scrutinizer ignore-call */ theme('table', array(
Loading history...
188
      'header' => $header,
189
      'rows' => $rows,
190
    ));
191
  }
192
}
193