CharacterEffectsCollection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A __construct() 0 2 1
A offsetUnset() 0 9 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
  protected string $class = CharacterEffect::class;
14
15 1
  public function __construct(private Character $character) {
16 1
    parent::__construct();
17 1
  }
18
19
  /**
20
   * @param int|NULL $index
21
   * @param CharacterEffect $item
22
   * @throws \OutOfRangeException
23
   * @throws \InvalidArgumentException
24
   * @throws \RuntimeException
25
   */
26
  public function offsetSet($index, $item): void {
27 1
    parent::offsetSet($index, $item);
28 1
    $item->onApply($this->character, $item);
29 1
  }
30
31
  /**
32
   * @param int $index
33
   * @throws \RuntimeException
34
   * @throws \OutOfRangeException
35
   */
36
  public function offsetUnset($index): void {
37
    try {
38
      /** @var CharacterEffect $item */
39 1
      $item = Arrays::get($this->items, $index);
40
    } catch(\Nette\InvalidArgumentException $e) {
41
      throw new \OutOfRangeException("Offset invalid or out of range.");
42
    }
43 1
    parent::offsetUnset($index);
44 1
    $item->onRemove($this->character, $item);
45 1
  }
46
}
47
?>