1 | <?php |
||
12 | class Calc { |
||
13 | |||
14 | const DICE_REGEX = '(?P<multiple>\d*)d(?P<dietype>\d+|f|\%|\[[^\]]+\]) |
||
15 | ( |
||
16 | (?P<keep>k(?:eep)?(?P<keepeval>[<>])(?P<keeprange>\d+)) |
||
17 | | |
||
18 | (?P<lowest>l(?:owest)?(?P<lowdice>\d+)) |
||
19 | | |
||
20 | (?P<highest>h(?:ighest)?(?P<highdice>\d+)) |
||
21 | | |
||
22 | (?P<reroll>r(?:eroll)?(?P<rerolleval>[<>])(?P<rerolllimit>\d+)) |
||
23 | | |
||
24 | (?P<openroll>o(?:pen)?(?P<openrolleval>[<>=])(?P<openrolllimit>\d+)) |
||
25 | | |
||
26 | (?P<flags>[z]+) |
||
27 | )*'; |
||
28 | |||
29 | /** |
||
30 | * @var array $ooo A list of operators with comparative order of operations |
||
31 | */ |
||
32 | private $ooo = [ |
||
33 | '>' => 0, |
||
34 | '<' => 0, |
||
35 | '=' => 0, |
||
36 | '-' => 10, |
||
37 | '+' => 10, |
||
38 | '*' => 20, |
||
39 | '/' => 20, |
||
40 | '^' => 30, |
||
41 | ]; |
||
42 | |||
43 | protected $expression; |
||
44 | protected $rpn = []; |
||
45 | protected $infix = []; |
||
46 | |||
47 | protected $stack = []; |
||
48 | |||
49 | /** |
||
50 | * Create a dice calculation |
||
51 | * |
||
52 | * @param string $expression An expression to calculate |
||
53 | */ |
||
54 | public function __construct($expression = '') { |
||
98 | |||
99 | /** |
||
100 | * @param int $numeral Numeral to add to the RPN stack |
||
101 | */ |
||
102 | protected function match_numeral($numeral) { |
||
106 | |||
107 | protected function match_dice($dice) { |
||
112 | |||
113 | protected function match_set($set) { |
||
117 | |||
118 | /** |
||
119 | * @param $variable |
||
120 | */ |
||
121 | protected function match_variable($variable) { |
||
125 | |||
126 | protected function match_parens($parenthesis) { |
||
137 | |||
138 | /** |
||
139 | * @param $operator |
||
140 | */ |
||
141 | protected function match_operator($operator) { |
||
154 | |||
155 | protected function clear_stack() { |
||
160 | |||
161 | /** |
||
162 | * @return mixed|string |
||
163 | * @throws \Exception |
||
164 | */ |
||
165 | public function __invoke() { |
||
199 | |||
200 | public function infix() { |
||
203 | |||
204 | } |
||
205 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.