CharacterEffectsCollection::offsetUnset()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

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