ContentModerationGraph   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A buildRow() 0 18 3
A create() 0 17 1
A buildGraph() 0 23 3
A report() 0 4 1
1
<?php
2
3
namespace Drupal\qa\Workflows;
4
5
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
6
use Drupal\Core\Entity\EntityStorageInterface;
7
use Drupal\Core\Entity\EntityTypeManagerInterface;
8
use Drupal\Core\StringTranslation\StringTranslationTrait;
9
use Grafizzi\Graph\Attribute;
0 ignored issues
show
Bug introduced by
The type Grafizzi\Graph\Attribute 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 Grafizzi\Graph\Edge;
0 ignored issues
show
Bug introduced by
The type Grafizzi\Graph\Edge 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 Grafizzi\Graph\Graph;
0 ignored issues
show
Bug introduced by
The type Grafizzi\Graph\Graph 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 Grafizzi\Graph\Node;
0 ignored issues
show
Bug introduced by
The type Grafizzi\Graph\Node 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 Monolog\Handler\StreamHandler;
0 ignored issues
show
Bug introduced by
The type Monolog\Handler\StreamHandler 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 Monolog\Logger;
0 ignored issues
show
Bug introduced by
The type Monolog\Logger 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...
15
use Pimple\Container;
0 ignored issues
show
Bug introduced by
The type Pimple\Container 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;
17
18
class ContentModerationGraph extends ContentModerationReportBase implements ContainerInjectionInterface {
0 ignored issues
show
Bug introduced by
The type Drupal\qa\Workflows\ContentModerationReportBase 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...
19
20
  use StringTranslationTrait;
21
22
  /**
23
   * The Pimple instance used by Grafizzi.
24
   *
25
   * @var \Pimple\Container
26
   */
27
  protected $pimple;
28
29
  public function __construct(EntityStorageInterface $stateStorage, EntityStorageInterface $transStorage, Container $pimple) {
30
    $this->pimple = $pimple;
31
    $this->stateStorage = $stateStorage;
0 ignored issues
show
Bug Best Practice introduced by
The property stateStorage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
32
    $this->transStorage = $transStorage;
0 ignored issues
show
Bug Best Practice introduced by
The property transStorage does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
  }
34
35
  /**
36
   * @return \Grafizzi\Graph\Graph
37
   */
38
  protected function buildGraph() {
39
    $dic = $this->pimple;
40
    $g = new Graph($dic);
41
    $states = $this->getStates();
42
    $transList = $this->getTrans();
43
44
    $nodes = [];
45
    foreach ($states as $name => $label) {
46
      $nodes[$name] = new Node($dic, $name, [
47
        new Attribute($dic, 'label', "${label}\n${name}"),
48
      ]);
49
      $g->addChild($nodes[$name]);
50
    }
51
52
    foreach ($transList as $name => $trans) {
53
      $g->addChild(new Edge($dic,
54
        $nodes[$trans['from']],
55
        $nodes[$trans['to']],
56
        [new Attribute($dic, 'label', "${trans['label']}\n$name")]
57
      ));
58
    }
59
60
    return $g;
61
  }
62
63
  protected function buildRow(string $stateId, array $transList) {
64
    $states = $this->getStates();
65
    $trans = $this->getTrans();
66
    $row = ["${states[$stateId]}\n${stateId}"];
67
    foreach ($transList as $from => $transIds) {
68
      $cellArray = [];
69
      foreach ($transIds as $transId) {
70
        assert($trans[$transId]['from'] = $stateId);
71
        $transLabel = $trans[$transId]['label'];
72
      }
73
      $cellArray[] = $transLabel;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $transLabel does not seem to be defined for all execution paths leading up to this point.
Loading history...
74
      $cellArray[] = $transId;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $transId does not seem to be defined for all execution paths leading up to this point.
Loading history...
75
      $cellArray[] = "";
76
      $cell = implode("\n", $cellArray);
77
      $row[$trans[$transId]['to']] = $cell;
78
    }
79
80
    return $row;
81
  }
82
83
  public static function create(ContainerInterface $container) {
84
    /** @var EntityTypeManagerInterface $etm */
85
    $etm = $container->get('entity_type.manager');
86
87
    $stateStorage = $etm->getStorage('moderation_state');
88
    $transStorage = $etm->getStorage('moderation_state_transition');
89
90
    $logger = new Logger(basename(__FILE__, '.php'));
91
    // Change the minimum logging level using the Logger:: constants.
92
    $logger->pushHandler(new StreamHandler('php://stderr', Logger::INFO));
93
94
    $pimple = new Container([
95
      'logger' => $logger,
96
      'directed' => TRUE,
97
    ]);
98
99
    return new static($stateStorage, $transStorage, $pimple);
100
  }
101
102
  public function report() {
103
    $grid = $this->buildGrid();
104
    return $this->buildGraph($grid)
0 ignored issues
show
Unused Code introduced by
The call to Drupal\qa\Workflows\Cont...tionGraph::buildGraph() has too many arguments starting with $grid. ( Ignorable by Annotation )

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

104
    return $this->/** @scrutinizer ignore-call */ buildGraph($grid)

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...
105
      ->build();
106
  }
107
108
}
109