Passed
Push — master ( d0ce80...210dba )
by Jakub
06:27
created

CharacterEffectsCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

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

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