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