Passed
Pull Request — master (#1816)
by Nico
31:00
created

PirateReactionMetadata   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getReactionAmount() 0 9 2
A addReaction() 0 8 2
1
<?php
2
3
namespace Stu\Lib\Pirate;
4
5
class PirateReactionMetadata
6
{
7
    /** @var array<int, int> $reactions */
8
    private array $reactions = [];
9
10 2
    public function addReaction(PirateBehaviourEnum $reaction): void
11
    {
12 2
        $key = $reaction->value;
13
14 2
        if (!array_key_exists($key, $this->reactions)) {
15 2
            $this->reactions[$key] = 1;
16
        } else {
17 1
            $this->reactions[$key]++;
18
        }
19
    }
20
21 3
    public function getReactionAmount(PirateBehaviourEnum $reaction): int
22
    {
23 3
        $key = $reaction->value;
24
25 3
        if (!array_key_exists($key, $this->reactions)) {
26 1
            return 0;
27
        }
28
29 2
        return $this->reactions[$key];
30
    }
31
}
32