GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b3985c...948e2f )
by Cees-Jan
09:54
created

PluginsCategories   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 11
Bugs 2 Features 4
Metric Value
dl 0
loc 87
ccs 26
cts 26
cp 1
rs 10
c 11
b 2
f 4
wmc 10
lcom 1
cbo 2

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getCategorySlug() 0 4 1
A setNode() 0 4 1
A getSlug() 0 4 1
A getConfiguration() 0 12 2
A getValues() 0 10 1
A getPluginCategories() 0 14 3
A getCapabilities() 0 4 1
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