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

ProjectsReportController::buildProjects()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 0
dl 0
loc 23
rs 9.7333
c 0
b 0
f 0
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 array<string,array|string>
53
   *   A render array
54
   */
55
  public function action() {
56
    $projects = $this->buildProjects();
57
    return $projects;
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
   * @deprecated
102
   */
103
  private final function qa_report_project(Variable $variable = NULL) {
104
    $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

104
    $c = /** @scrutinizer ignore-call */ cache_get('views_data:fr', 'cache_views');
Loading history...
105
    $ret = '<pre>' . json_encode($c, JSON_PRETTY_PRINT) . '</pre>';
106
    return $ret;
107
    $bc = drupal_get_breadcrumb();
0 ignored issues
show
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

107
    $bc = /** @scrutinizer ignore-call */ drupal_get_breadcrumb();
Loading history...
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...
108
    $bc[] = l($this->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

108
    $bc[] = /** @scrutinizer ignore-call */ l($this->t('Administration'), 'admin');
Loading history...
109
    $bc[] = l($this->t('Reports'), 'admin/reports');
110
    $bc[] = l($this->t('Quality Assurance'), 'admin/reports/qa');
111
    $bc[] = l($this->t('Variables'), 'admin/reports/qa/variable');
112
    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

112
    /** @scrutinizer ignore-call */ 
113
    drupal_set_breadcrumb($bc);
Loading history...
113
114
    drupal_set_title($this->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

114
    /** @scrutinizer ignore-call */ 
115
    drupal_set_title($this->t('Variable: %name', array('%name' => $variable->name)), PASS_THROUGH);
Loading history...
115
    return $variable->dump();
116
  }
117
118
  /**
119
   * Page callback for projects list.
120
   *
121
   * @return string
122
   *
123
   * @FIXME This still uses the D7 info structure.
124
   *
125
   * @deprecated
126
   */
127
  private final function qa_report_projects() {
128
    $ret = '<h3>Projects</h3>';
129
    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

129
    /** @scrutinizer ignore-call */ 
130
    drupal_static_reset('update_get_projects');
Loading history...
130
    $GLOBALS['conf']['update_check_disabled'] = TRUE;
131
    $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

131
    $projects = /** @scrutinizer ignore-call */ update_get_projects();
Loading history...
132
    ksort($projects);
133
    $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

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

191
    return /** @scrutinizer ignore-call */ theme('table', array(
Loading history...
192
      'header' => $header,
193
      'rows' => $rows,
194
    ));
195
  }
196
}
197