Passed
Push — master ( ff1e5a...9ad4f6 )
by Jakub
02:27
created

CombatActionSelector   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

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

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
use HeroesofAbenez\Combat\CombatActions\ICombatAction;
7
8
/**
9
 * CombatActionSelector
10
 *
11
 * @author Jakub Konečný
12
 */
13 1
final class CombatActionSelector implements ICombatActionSelector {
14 1
  use \Nette\SmartObject;
15
16
  public function chooseAction(CombatBase $combat, Character $character): ?string {
17 1
    if($character->hitpoints < 1) {
18
      return null;
19
    }
20
    /** @var ICombatAction[] $actions */
21 1
    $actions = $combat->combatActions->toArray();
22 1
    usort($actions, function(ICombatAction $a, ICombatAction $b) {
23 1
      return $a->getPriority() < $b->getPriority();
24 1
    });
25 1
    foreach($actions as $action) {
26 1
      if($action->shouldUse($combat, $character)) {
27 1
        return $action->getName();
28
      }
29
    }
30
    return null;
31
  }
32
}
33
?>