Test Failed
Push — master ( 4204bb...4b507f )
by Jakub
02:18
created

CombatActionSelector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 4
eloc 11
c 5
b 0
f 1
dl 0
loc 18
ccs 10
cts 11
cp 0.9091
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A chooseAction() 0 15 4
1
<?php
2
declare(strict_types=1);
3
4
namespace HeroesofAbenez\Combat;
5
6
/**
7
 * CombatActionSelector
8
 *
9
 * @author Jakub Konečný
10
 */
11 1
final class CombatActionSelector implements ICombatActionSelector {
12
  use \Nette\SmartObject;
13
14
  public function chooseAction(CombatBase $combat, Character $character): ?ICombatAction {
15 1
    if($character->hitpoints < 1) {
16 1
      return null;
17
    }
18
    /** @var ICombatAction[] $actions */
19 1
    $actions = $combat->combatActions->toArray();
20 1
    usort($actions, function(ICombatAction $a, ICombatAction $b): int {
21 1
      return $a->getPriority() <=> $b->getPriority();
22 1
    });
23 1
    foreach($actions as $action) {
24 1
      if($action->shouldUse($combat, $character)) {
25 1
        return $action;
26
      }
27
    }
28
    return null;
29
  }
30
}
31
?>