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.

Uptime   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 108
Duplicated Lines 14.81 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 2 Features 3
Metric Value
dl 16
loc 108
ccs 31
cts 31
cp 1
rs 10
wmc 9
lcom 2
cbo 2
c 10
b 2
f 3

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getCategorySlug() 0 4 1
A __construct() 0 4 1
A setNode() 0 4 1
A getSlug() 0 4 1
A getConfiguration() 16 16 2
A getValues() 0 6 1
A getUptimeValue() 0 8 1
A getCapabilities() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Metric;
18
use WyriHaximus\PhuninNode\Node;
19
use WyriHaximus\PhuninNode\PluginInterface;
20
use function React\Promise\resolve;
21
use function WyriHaximus\PhuninNode\metricPromisesToObjectStorage;
22
23
/**
24
 * Class Uptime
25
 * @package WyriHaximus\PhuninNode\Plugins
26
 */
27
class Uptime implements PluginInterface
28
{
29
    /**
30
     * Seconds in a day
31
     */
32
    const DAY_IN_SECONDS = 86400;
33
34
    /**
35
     * @var Node
36
     */
37
    private $node;
38
39
    /**
40
     * Cached configuration state
41
     *
42
     * @var Configuration
43
     */
44
    private $configuration;
45
46
    /**
47
     * Start time of this instance
48
     *
49
     * @var int
50
     */
51
    private $startTime = 0;
52
53
    /**
54
     * Save the time this instance started
55
     */
56 8
    public function __construct()
57
    {
58 8
        $this->startTime = time();
59 8
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 8
    public function setNode(Node $node)
65
    {
66 8
        $this->node = $node;
67 8
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1
    public function getSlug(): string
73
    {
74 1
        return 'uptime';
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 1
    public function getCategorySlug(): string
81
    {
82 1
        return 'phunin_node';
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88 2 View Code Duplication
    public function getConfiguration(): PromiseInterface
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
    {
90 2
        if ($this->configuration instanceof Configuration) {
91 1
            return resolve($this->configuration);
92
        }
93
94 2
        $this->configuration = new Configuration();
95 2
        $this->configuration->setPair('graph_category', 'phunin_node');
96 2
        $this->configuration->setPair('graph_title', 'Uptime');
97 2
        $this->configuration->setPair('graph_args', '--base 1000 -l 0');
98 2
        $this->configuration->setPair('graph_vlabel', 'uptime in days');
99 2
        $this->configuration->setPair('uptime.label', 'uptime');
100 2
        $this->configuration->setPair('uptime.draw', 'AREA');
101
102 2
        return resolve($this->configuration);
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108 2
    public function getValues(): PromiseInterface
109
    {
110 2
        return metricPromisesToObjectStorage([
111 2
            $this->getUptimeValue(),
112
        ]);
113
    }
114
115
    /**
116
     * @return Metric
117
     */
118 2
    private function getUptimeValue(): Metric
119
    {
120 2
        $value = new Metric(
121 2
            'uptime',
122 2
            ((time() - $this->startTime) / self::DAY_IN_SECONDS)
123
        );
124 2
        return $value;
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130 1
    public function getCapabilities(): array
131
    {
132 1
        return [];
133
    }
134
}
135