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

CheckListController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 32
c 1
b 0
f 0
dl 0
loc 82
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A view() 0 4 1
A __construct() 0 2 1
A create() 0 3 1
B report() 0 34 6
1
<?php
2
3
namespace Drupal\qa\Controller;
4
5
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...
6
use Drupal\qa\Data;
7
use Drupal\qa\Plugin\QaCheckManager;
8
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...
9
10
/**
11
 * Class ControlsListController.
12
 *
13
 * @package Drupal\qa\Controller
14
 */
15
class CheckListController extends ControllerBase {
16
17
  /**
18
   * The plugin.manager.qa_check service.
19
   *
20
   * @var \Drupal\qa\Plugin\QaCheckManager
21
   */
22
  protected $qam;
23
24
  /**
25
   * CheckListController constructor.
26
   *
27
   * @param \Drupal\qa\Plugin\QaCheckManager $qam
28
   *   The plugin.manager.qa_check service.
29
   */
30
  public function __construct(QaCheckManager $qam) {
31
    $this->qam = $qam;
32
  }
33
34
  /**
35
   * {@inheritdoc}
36
   */
37
  public static function create(ContainerInterface $container) {
38
    $qam = $container->get(Data::MANAGER);
39
    return new static($qam);
40
  }
41
42
  /**
43
   * Controller listing the available plugins.
44
   *
45
   * @return array
46
   *   A render array.
47
   */
48
  public function report() {
49
    $checks = [
50
      '#theme' => 'item_list',
51
      '#items' => [],
52
    ];
53
    $pp = $this->qam->getPluginsByPackage();
54
    foreach ($pp as $package => $plugins) {
55
      $group = [
56
        '#theme' => 'item_list',
57
        '#items' => [],
58
        '#title' => ucfirst($package),
59
      ];
60
      foreach ($plugins as $def) {
61
        $label = $def['label'];
62
        $props = [];
63
        if ($def['usesBatch'] ?? FALSE) {
64
          $props[] = $this->t('batch');
65
        }
66
        if (($def['steps'] ?? 1) > 1) {
67
          $props[] = $this->formatPlural($def['steps'], "1 step",
68
            "@count steps", ['@count' => $def['steps']],
69
          );
70
        }
71
        if (!empty($props)) {
72
          $label .= ' (' . implode(', ', $props) . ')';
73
        }
74
        $details = $def['details'];
75
        $group['#items'][] = [
76
          '#markup' => "${label}<br /><small>${details}</small>",
77
        ];
78
      }
79
      $checks['#items'][] = $group;
80
    }
81
    return $checks;
82
  }
83
84
  /**
85
   * Placeholder controller for "view".
86
   *
87
   * @param string $qaVariable
88
   *   The variable to view.
89
   *
90
   * @return array
91
   *   A render array.
92
   */
93
  public function view($qaVariable) {
94
    return [
95
      '#type' => 'markup',
96
      '#markup' => $this->t('Implement method: view'),
97
    ];
98
  }
99
100
}
101