1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
/* |
5
|
|
|
* This file is part of PhuninNode. |
6
|
|
|
* |
7
|
|
|
** (c) 2013 - 2016 Cees-Jan Kiewiet |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WyriHaximus\PhuninNode\Plugins; |
14
|
|
|
|
15
|
|
|
use React\Promise\PromiseInterface; |
16
|
|
|
use WyriHaximus\PhuninNode\Configuration; |
17
|
|
|
use WyriHaximus\PhuninNode\Node; |
18
|
|
|
use WyriHaximus\PhuninNode\PluginInterface; |
19
|
|
|
use function React\Promise\resolve; |
20
|
|
|
use function WyriHaximus\PhuninNode\arrayToMetricPromises; |
21
|
|
|
use function WyriHaximus\PhuninNode\metricPromisesToObjectStorage; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Class PluginsCategories |
25
|
|
|
* @package WyriHaximus\PhuninNode\Plugins |
26
|
|
|
*/ |
27
|
|
|
class PluginsCategories implements PluginInterface |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @var Node |
31
|
|
|
*/ |
32
|
|
|
private $node; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
7 |
|
public function setNode(Node $node) |
38
|
|
|
{ |
39
|
7 |
|
$this->node = $node; |
40
|
7 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
1 |
|
public function getSlug(): string |
46
|
|
|
{ |
47
|
1 |
|
return 'plugins_categories'; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* {@inheritdoc} |
52
|
|
|
*/ |
53
|
1 |
|
public function getCategorySlug(): string |
54
|
|
|
{ |
55
|
1 |
|
return 'phunin_node'; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* {@inheritdoc} |
60
|
|
|
*/ |
61
|
2 |
|
public function getConfiguration(): PromiseInterface |
62
|
|
|
{ |
63
|
2 |
|
$configuration = new Configuration(); |
64
|
2 |
|
$configuration->setPair('graph_category', 'phunin_node'); |
65
|
2 |
|
$configuration->setPair('graph_title', 'Plugins Per Category'); |
66
|
|
|
|
67
|
2 |
|
foreach ($this->getPluginCategories() as $key => $value) { |
68
|
2 |
|
$configuration->setPair($key . '.label', $key); |
69
|
|
|
} |
70
|
|
|
|
71
|
2 |
|
return resolve($configuration); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* {@inheritdoc} |
76
|
|
|
*/ |
77
|
2 |
|
public function getValues(): PromiseInterface |
78
|
|
|
{ |
79
|
2 |
|
return metricPromisesToObjectStorage( |
80
|
|
|
iterator_to_array( |
81
|
|
|
arrayToMetricPromises( |
82
|
2 |
|
$this->getPluginCategories() |
83
|
|
|
) |
84
|
|
|
) |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
4 |
|
private function getPluginCategories(): array |
92
|
|
|
{ |
93
|
4 |
|
$categories = []; |
94
|
4 |
|
$plugins = $this->node->getPlugins(); |
95
|
4 |
|
foreach ($plugins as $plugin) { |
96
|
4 |
|
$category = $plugin->getCategorySlug(); |
97
|
4 |
|
if (!isset($categories[$category])) { |
98
|
4 |
|
$categories[$category] = 0; |
99
|
|
|
} |
100
|
4 |
|
$categories[$category]++; |
101
|
|
|
} |
102
|
|
|
|
103
|
4 |
|
return $categories; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
*/ |
109
|
|
|
public function getCapabilities(): array |
110
|
|
|
{ |
111
|
|
|
return []; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|