Metrics   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 61
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 8 2
A sub() 0 8 2
A observe() 0 8 2
A set() 0 8 2
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
declare(strict_types=1);
10
11
namespace Spiral\RoadRunner;
12
13
use Spiral\Goridge\Exceptions\RPCException;
14
use Spiral\Goridge\RPC;
15
use Spiral\RoadRunner\Exception\MetricException;
16
17
/**
18
 * Application metrics.
19
 */
20
final class Metrics implements MetricsInterface
21
{
22
    /** @var RPC */
23
    private $rpc;
24
25
    /**
26
     * @param RPC $rpc
27
     */
28
    public function __construct(RPC $rpc)
29
    {
30
        $this->rpc = $rpc;
31
    }
32
33
    /**
34
     * @inheritDoc
35
     */
36
    public function add(string $name, float $value, array $labels = []): void
37
    {
38
        try {
39
            $this->rpc->call('metrics.Add', compact('name', 'value', 'labels'));
40
        } catch (RPCException $e) {
41
            throw new MetricException($e->getMessage(), $e->getCode(), $e);
42
        }
43
    }
44
45
    /**
46
     * @inheritDoc
47
     */
48
    public function sub(string $name, float $value, array $labels = []): void
49
    {
50
        try {
51
            $this->rpc->call('metrics.Sub', compact('name', 'value', 'labels'));
52
        } catch (RPCException $e) {
53
            throw new MetricException($e->getMessage(), $e->getCode(), $e);
54
        }
55
    }
56
57
    /**
58
     * @inheritDoc
59
     */
60
    public function observe(string $name, float $value, array $labels = []): void
61
    {
62
        try {
63
            $this->rpc->call('metrics.Observe', compact('name', 'value', 'labels'));
64
        } catch (RPCException $e) {
65
            throw new MetricException($e->getMessage(), $e->getCode(), $e);
66
        }
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function set(string $name, float $value, array $labels = []): void
73
    {
74
        try {
75
            $this->rpc->call('metrics.Set', compact('name', 'value', 'labels'));
76
        } catch (RPCException $e) {
77
            throw new MetricException($e->getMessage(), $e->getCode(), $e);
78
        }
79
    }
80
}
81