Test Failed
Push — main ( d2d042...ea42f2 )
by Bingo
13:21
created

Meter::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Jabe\Engine\Impl\Metrics;
4
5
class Meter
6
{
7
    protected $counter;
8
9
    protected $name;
10
11
    public function __construct(string $name)
12
    {
13
        $this->name = $name;
14
        $this->counter = new \Swoole\Atomic\Long(0);
15
    }
16
17
    public function mark(): void
18
    {
19
        $this->counter->add(1);
20
    }
21
22
    public function markTimes(int $times): void
23
    {
24
        $this->counter->add($times);
25
    }
26
27
    public function getName(): string
28
    {
29
        return $this->name;
30
    }
31
32
    public function setName(string $name): void
33
    {
34
        $this->name = $name;
35
    }
36
37
    public function getAndClear(): int
38
    {
39
        $prev = $this->counter->get();
40
        $this->counter->set(0);
41
        return $prev;
42
    }
43
44
    public function get(bool $clear = false): int
45
    {
46
        return $clear ? $this->getAndClear() : $this->counter->get();
47
    }
48
}
49