StoredMetricMutator::findOrCreateMetric()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 1
nc 1
nop 2
crap 2
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