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

Meter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 13
c 1
b 0
f 0
dl 0
loc 42
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A markTimes() 0 3 1
A __construct() 0 4 1
A setName() 0 3 1
A getAndClear() 0 5 1
A getName() 0 3 1
A mark() 0 3 1
A get() 0 3 2
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