Completed
Push — master ( 516660...f56fd8 )
by Cees-Jan
06:37
created

GlobalState   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 43.24 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 16
loc 37
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A reset() 0 4 1
A set() 0 4 1
A incr() 8 8 2
A decr() 8 8 2

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 declare(strict_types=1);
2
3
namespace WyriHaximus\React\Inspector;
4
5
final class GlobalState
6
{
7
    protected static $state = [];
8
9
    public static function get(): array
10
    {
11
        return self::$state;
12
    }
13
14
    public static function reset()
15
    {
16
        self::$state = [];
17
    }
18
19
    public static function set(string $key, int $value)
20
    {
21
        self::$state[$key] = $value;
22
    }
23
24 View Code Duplication
    public static function incr(string $key, int $value = 1)
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...
25
    {
26
        if (!isset(self::$state[$key])) {
27
            self::$state[$key] = 0;
28
        }
29
30
        self::$state[$key] += $value;
31
    }
32
33 View Code Duplication
    public static function decr(string $key, int $value = 1)
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...
34
    {
35
        if (!isset(self::$state[$key])) {
36
            self::$state[$key] = 0;
37
        }
38
39
        self::$state[$key] -= $value;
40
    }
41
}
42