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

CharacterEffectsCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 37
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetSet() 0 3 1
A __construct() 0 3 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 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
?>