| Conditions | 2 |
| Paths | 2 |
| Total Lines | 17 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 2 |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | public function calculateInitiative(Character $character): int |
||
| 14 | { |
||
| 15 | 1 | $result = 0; |
|
| 16 | 1 | $formula = $character->initiativeFormula; |
|
| 17 | 1 | $stats = [ |
|
| 18 | 1 | "INT" => (string) $character->intelligence, "DEX" => (string) $character->dexterity, |
|
| 19 | 1 | "STR" => (string) $character->strength, "CON" => (string) $character->constitution, |
|
| 20 | 1 | "CHAR" => (string) $character->charisma, |
|
| 21 | ]; |
||
| 22 | 1 | $formula = str_replace(array_keys($stats), array_values($stats), $formula); |
|
| 23 | 1 | preg_match("/^([1-9]+)d([1-9]+)/", $formula, $dices); |
|
| 24 | 1 | for ($i = 1; $i <= (int) $dices[1]; $i++) { |
|
| 25 | 1 | $result += rand(1, (int) $dices[2]); |
|
| 26 | } |
||
| 27 | 1 | preg_match("/\+([0-9]+)\/([0-9]+)/", $formula, $ammendum); |
|
| 28 | 1 | $result += (int) $ammendum[1] / (int) $ammendum[2]; |
|
| 29 | 1 | return (int) $result; |
|
| 30 | } |
||
| 32 |