Passed
Push — master ( 829174...1eed22 )
by Jakub
01:43
created

CharacterEffectsCollection::offsetUnset()   A

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 0
Metric Value
eloc 6
dl 0
loc 9
ccs 3
cts 5
cp 0.6
rs 10
c 0
b 0
f 0
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 1
final class CharacterEffectsCollection extends \Nexendrie\Utils\Collection {
13
  /** @var string */
14
  protected $class = CharacterEffect::class;
15
  /** @var Character */
16
  protected $character;
17
18
  public function __construct(Character $character) {
19 1
    parent::__construct();
20 1
    $this->character = $character;
21 1
  }
22
23
  /**
24
   * @param int|NULL $index
25
   * @param CharacterEffect $item
26
   * @throws \OutOfRangeException
27
   * @throws \InvalidArgumentException
28
   * @throws \RuntimeException
29
   */
30
  public function offsetSet($index, $item): void {
31 1
    parent::offsetSet($index, $item);
32 1
    $item->onApply($this->character, $item);
33 1
  }
34
35
  /**
36
   * @param int $index
37
   * @throws \RuntimeException
38
   * @throws \OutOfRangeException
39
   */
40
  public function offsetUnset($index): void {
41
    try {
42
      /** @var CharacterEffect $item */
43 1
      $item = Arrays::get($this->items, $index);
44
    } catch(\Nette\InvalidArgumentException $e) {
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
?>