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; |
|
|
|
|
10
|
|
|
use Grafizzi\Graph\Edge; |
|
|
|
|
11
|
|
|
use Grafizzi\Graph\Graph; |
|
|
|
|
12
|
|
|
use Grafizzi\Graph\Node; |
|
|
|
|
13
|
|
|
use Monolog\Handler\StreamHandler; |
|
|
|
|
14
|
|
|
use Monolog\Logger; |
|
|
|
|
15
|
|
|
use Pimple\Container; |
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
17
|
|
|
|
18
|
|
|
class ContentModerationGraph extends ContentModerationReportBase implements ContainerInjectionInterface { |
|
|
|
|
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; |
|
|
|
|
32
|
|
|
$this->transStorage = $transStorage; |
|
|
|
|
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; |
|
|
|
|
74
|
|
|
$cellArray[] = $transId; |
|
|
|
|
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) |
|
|
|
|
105
|
|
|
->build(); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths