This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace DiceCalc; |
||
4 | |||
5 | /** |
||
6 | * Class CalcSet |
||
7 | * |
||
8 | * @package DiceCalc |
||
9 | * @author Owen Winkler <[email protected]> |
||
10 | * @license MIT http://opensource.org/licenses/MIT |
||
11 | */ |
||
12 | class CalcSet { |
||
13 | protected $values = []; |
||
14 | protected $label; |
||
15 | |||
16 | public function __construct($set_value) { |
||
17 | if (is_array($set_value)) { |
||
18 | $this->values = $set_value; |
||
19 | $this->saved_values = $this->values; |
||
0 ignored issues
–
show
|
|||
20 | $this->label = '[' . implode(', ', $set_value) . ']'; |
||
21 | } else { |
||
22 | $this->label = $set_value; |
||
23 | preg_match('%^(?P<multiple>\d*)\[(?P<set>[^\]]+)\]$%i', $set_value, $matches); |
||
24 | $set_value = $matches['set']; |
||
25 | $values = explode(',', $set_value); |
||
26 | for ($z = 0; $z < max(1, intval($matches['multiple'])); $z ++) { |
||
0 ignored issues
–
show
Consider avoiding function calls on each iteration of the
for loop.
If you have a function call in the test part of a // count() is called on each iteration
for ($i=0; $i < count($collection); $i++) { }
// count() is only called once
for ($i=0, $c=count($collection); $i<$c; $i++) { }
![]() |
|||
27 | foreach ($values as $set_value) { |
||
28 | $this->values[] = $set_value; |
||
29 | } |
||
30 | } |
||
31 | $this->saved_values = $this->values; |
||
0 ignored issues
–
show
The property
saved_values does not seem to exist. Did you mean values ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
32 | foreach ($this->values as $k => $set_value) { |
||
33 | $calc = new Calc($set_value); |
||
34 | $this->values[$k] = $calc(); |
||
35 | } |
||
36 | foreach ($this->values as $k => $value) { |
||
37 | $calc = new Calc($value); |
||
38 | $this->values[$k] = $calc(); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | public function __toString() { |
||
44 | $out = []; |
||
45 | foreach (array_keys($this->saved_values) as $key) { |
||
0 ignored issues
–
show
The property
saved_values does not seem to exist. Did you mean values ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
46 | $vout = $this->values[$key]; |
||
47 | if (!isset($this->values[$key])) { |
||
48 | $vout = $this->saved_values[$key]; |
||
0 ignored issues
–
show
The property
saved_values does not seem to exist. Did you mean values ?
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name. If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading. ![]() |
|||
49 | } |
||
50 | if ($vout === true) { |
||
51 | $vout = '<span class="true">true</span>'; |
||
52 | } |
||
53 | if ($vout === false) { |
||
54 | $vout = '<span class="false">false</span>'; |
||
55 | } |
||
56 | if (isset($this->values[$key])) { |
||
57 | $out[] = $vout; |
||
58 | } else { |
||
59 | $out[] = '<s>' . $vout . '</s>'; |
||
60 | } |
||
61 | } |
||
62 | $out = '[' . implode(', ', $out) . ']'; |
||
63 | |||
64 | return $out; |
||
65 | } |
||
66 | |||
67 | View Code Duplication | public function calc($operator, $operand) { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
68 | $out = []; |
||
69 | foreach ($this->values as $value) { |
||
70 | $out[] = CalcOperation::calc($operator, $operand, $value); |
||
71 | } |
||
72 | |||
73 | return new CalcSet($out); |
||
74 | } |
||
75 | |||
76 | View Code Duplication | public function rcalc($operator, $operand) { |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
77 | $out = []; |
||
78 | foreach ($this->values as $value) { |
||
79 | $out[] = CalcOperation::calc($operator, $value, $operand); |
||
80 | } |
||
81 | |||
82 | return new CalcSet($out); |
||
83 | } |
||
84 | |||
85 | View Code Duplication | public function mcalc($operator, $operand) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
86 | { |
||
87 | $out = []; |
||
88 | foreach ($this->values as $value) { |
||
89 | $out[] = $operand->rcalc($operator, $value); |
||
90 | } |
||
91 | |||
92 | return new CalcSet($out); |
||
93 | } |
||
94 | |||
95 | public function value() |
||
96 | { |
||
97 | $allnumeric = true; |
||
98 | foreach ($this->values as $v) { |
||
99 | if (is_numeric($v)) { |
||
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. ![]() |
|||
100 | } else { |
||
101 | $allnumeric = false; |
||
102 | } |
||
103 | } |
||
104 | |||
105 | if ($allnumeric) { |
||
106 | return array_sum($this->values); |
||
107 | } else { |
||
108 | return $this; |
||
109 | } |
||
110 | } |
||
111 | } |
||
112 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.