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

CharacterEffectsCollection::offsetSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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