CharacterEffectsCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 11
c 2
b 0
f 0
dl 0
loc 37
rs 10
ccs 9
cts 11
cp 0.8182

3 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 4 1
A __construct() 0 3 1
A offsetUnset() 0 10 2
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
use Nette\Utils\Arrays;
7
8
/**
9
 * @author Jakub Konečný
10
 * @internal
11
 */
12
final class CharacterEffectsCollection extends \Nexendrie\Utils\Collection
13
{
14
    protected string $class = CharacterEffect::class;
15
16 1
    public function __construct(private readonly Character $character)
17
    {
18 1
        parent::__construct();
19 1
    }
20
21
    /**
22
     * @param int|NULL $index
23
     * @param CharacterEffect $item
24
     * @throws \OutOfRangeException
25
     * @throws \InvalidArgumentException
26
     * @throws \RuntimeException
27
     */
28
    public function offsetSet($index, $item): void
29
    {
30 1
        parent::offsetSet($index, $item);
31 1
        $item->onApply($this->character, $item);
32 1
    }
33
34
    /**
35
     * @param int $index
36
     * @throws \RuntimeException
37
     * @throws \OutOfRangeException
38
     */
39
    public function offsetUnset($index): void
40
    {
41
        try {
42
            /** @var CharacterEffect $item */
43 1
            $item = Arrays::get($this->items, $index);
44
        } catch (\Nette\InvalidArgumentException) {
45
            throw new \OutOfRangeException("Offset invalid or out of range.");
46
        }
47 1
        parent::offsetUnset($index);
48 1
        $item->onRemove($this->character, $item);
49 1
    }
50
}
51