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 ( e6a421...730d79 )
by Cees-Jan
06:02
created

Pool::getCapabilities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of PhuninNode.
6
 *
7
 ** (c) 2013 - 2015 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\React\ChildProcess\Pool\PhuninNode;
14
15
use React\Promise\PromiseInterface;
16
use WyriHaximus\PhuninNode\Configuration;
17
use WyriHaximus\PhuninNode\Metric;
18
use WyriHaximus\PhuninNode\Node;
19
use WyriHaximus\PhuninNode\PluginInterface;
20
use WyriHaximus\React\ChildProcess\Pool\Info;
21
use WyriHaximus\React\ChildProcess\Pool\PoolInfoInterface;
22
use function React\Promise\resolve;
23
24
/**
25
 * Class MemoryUsage
26
 * @package WyriHaximus\PhuninNode\Plugins
27
 */
28
class Pool implements PluginInterface
29
{
30
    /**
31
     * @var PoolInfoInterface
32
     */
33
    protected $pool;
34
35
    /**
36
     * @var string
37
     */
38
    protected $title;
39
40
    /**
41
     * @var string
42
     */
43
    protected $slug;
44
45
    /**
46
     * @var string
47
     */
48
    protected $categorySlug;
49
50
    /**
51
     * @var Node
52
     */
53
    private $node;
54
55
    /**
56
     * Cached configuration state
57
     *
58
     * @var Configuration
59
     */
60
    private $configuration;
61
62
    /**
63
     * Pool constructor.
64
     * @param PoolInfoInterface $pool
65
     * @param string $slug
66
     * @param string $categorySlug
67
     * @param string $title
68
     */
69 7
    public function __construct(PoolInfoInterface $pool, $title, $slug, $categorySlug)
70
    {
71 7
        $this->pool = $pool;
72 7
        $this->title = $title;
73 7
        $this->slug = $slug;
74 7
        $this->categorySlug = $categorySlug;
75 7
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 7
    public function setNode(Node $node)
81
    {
82 7
        $this->node = $node;
83 7
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88 1
    public function getSlug(): string
89
    {
90 1
        return $this->slug;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96 1
    public function getCategorySlug(): string
97
    {
98 1
        return $this->categorySlug;
99
    }
100
    
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function getCapabilities(): array
105
    {
106
        return [];
107
    }
108
    
109
    /**
110
     * {@inheritdoc}
111
     */
112 2
    public function getConfiguration(): PromiseInterface
113
    {
114 2
        if ($this->configuration instanceof Configuration) {
115 1
            return resolve($this->configuration);
116
        }
117
118 2
        $this->configuration = new Configuration();
119 2
        $this->configuration->setPair('graph_category', $this->categorySlug);
120 2
        $this->configuration->setPair('graph_title', $this->title);
121 2
        $this->configuration->setPair('current_size.label', 'Current Pool size');
122 2
        $this->configuration->setPair('current_queued_calls.label', 'Current Queued call count');
123 2
        $this->configuration->setPair('current_busy.label', 'Current Busy worker count');
124 2
        $this->configuration->setPair('current_idle_workers.label', 'Current Idle Workers count');
125
126 2
        return resolve($this->configuration);
127
    }
128
129
    /**
130
     * {@inheritdoc}
131
     */
132 2
    public function getValues(): PromiseInterface
133
    {
134 2
        $info = $this->pool->info();
135 2
        $storage = new \SplObjectStorage();
136 2
        $storage->attach(new Metric('current_size', (float)$info[Info::SIZE]));
137 2
        $storage->attach(new Metric('current_busy', (float)$info[Info::BUSY]));
138 2
        $storage->attach(new Metric('current_queued_calls', (float)$info[Info::CALLS]));
139 2
        $storage->attach(new Metric('current_idle_workers', (float)$info[Info::IDLE]));
140 2
        return resolve($storage);
141
    }
142
}
143