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

PirateReactionMetadata::addReaction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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