StoredMetricMutator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 6
dl 0
loc 25
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findOrCreateMetric() 0 3 2
A adjustMetricValue() 0 3 1
A setMetricValue() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Lamoda\Metric\Storage;
4
5
final class StoredMetricMutator implements MetricMutatorInterface
6
{
7
    /** @var MetricStorageInterface */
8
    private $storage;
9
10 4
    public function __construct(MetricStorageInterface $storage)
11
    {
12 4
        $this->storage = $storage;
13 4
    }
14
15
    /** {@inheritdoc} */
16 2
    public function adjustMetricValue(float $delta, string $name, array $tags = []): void
17
    {
18 2
        $this->findOrCreateMetric($name, $tags)->adjust($delta);
19 2
    }
20
21
    /** {@inheritdoc} */
22 2
    public function setMetricValue(float $value, string $name, array $tags = []): void
23
    {
24 2
        $this->findOrCreateMetric($name, $tags)->setValue($value);
25 2
    }
26
27 4
    private function findOrCreateMetric(string $name, array $tags): MutableMetricInterface
28
    {
29 4
        return $this->storage->findMetric($name, $tags) ?: $this->storage->createMetric($name, 0, $tags);
30
    }
31
}
32