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 | namespace Redaxscript; |
||
3 | |||
4 | use function is_numeric; |
||
5 | use function random_int; |
||
6 | |||
7 | /** |
||
8 | * parent class to provide a mathematical task |
||
9 | * |
||
10 | * @since 2.0.0 |
||
11 | * |
||
12 | * @package Redaxscript |
||
13 | * @category Captcha |
||
14 | * @author Henry Ruhs |
||
15 | */ |
||
16 | |||
17 | class Captcha |
||
18 | { |
||
19 | /** |
||
20 | * captcha operator mode |
||
21 | * |
||
22 | * @var int |
||
23 | */ |
||
24 | |||
25 | protected int $_mode; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
26 | |||
27 | /** |
||
28 | * task to be solved |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | |||
33 | protected string $_task; |
||
34 | |||
35 | /** |
||
36 | * solution to the task |
||
37 | * |
||
38 | * @var int |
||
39 | */ |
||
40 | |||
41 | protected string $_solution; |
||
42 | |||
43 | /** |
||
44 | * allowed range for the task |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | |||
49 | protected array $_rangeArray = |
||
50 | [ |
||
51 | 'min' => 1, |
||
52 | 'max' => 10 |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * array of mathematical operators used for the task |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | |||
61 | protected array $_operatorArray = |
||
62 | [ |
||
63 | 1 => 'plus', |
||
64 | -1 => 'minus' |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * constructor of the class |
||
69 | * |
||
70 | * @since 2.4.0 |
||
71 | * |
||
72 | * @param Language $_language instance of the language class |
||
73 | */ |
||
74 | |||
75 | public function __construct(protected Language $_language) |
||
76 | { |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * init the class |
||
81 | * |
||
82 | * @since 2.4.0 |
||
83 | 5 | * |
|
84 | * @param int $mode captcha operator mode |
||
85 | 5 | */ |
|
86 | 5 | ||
87 | public function init(int $mode = null) : void |
||
88 | { |
||
89 | if (is_numeric($mode)) |
||
90 | { |
||
91 | $this->_mode = $mode; |
||
92 | } |
||
93 | else |
||
94 | { |
||
95 | $settingModel = new Model\Setting(); |
||
96 | 5 | $this->_mode = $settingModel->get('captcha'); |
|
97 | } |
||
98 | 5 | $this->_create(); |
|
99 | } |
||
100 | 2 | ||
101 | /** |
||
102 | * get the task |
||
103 | * |
||
104 | 3 | * @since 2.0.0 |
|
105 | 3 | * |
|
106 | * @return string |
||
107 | 5 | */ |
|
108 | 5 | ||
109 | public function getTask() : string |
||
110 | { |
||
111 | return $this->_task; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * get the solution |
||
116 | * |
||
117 | * @since 2.6.0 |
||
118 | 1 | * |
|
119 | * @return int |
||
120 | 1 | */ |
|
121 | |||
122 | public function getSolution() : int |
||
123 | { |
||
124 | return $this->_solution; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * get the minimum range |
||
129 | * |
||
130 | * @since 2.6.0 |
||
131 | 3 | * |
|
132 | * @return int |
||
133 | 3 | */ |
|
134 | |||
135 | public function getMin() : int |
||
136 | { |
||
137 | return $this->_rangeArray['min']; |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * get the maximum range |
||
142 | * |
||
143 | * @since 2.6.0 |
||
144 | 5 | * |
|
145 | * @return int |
||
146 | 5 | */ |
|
147 | |||
148 | public function getMax() : int |
||
149 | { |
||
150 | return $this->_rangeArray['max']; |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * get the mathematical operator used for the task |
||
155 | * |
||
156 | * @since 2.0.0 |
||
157 | 5 | * |
|
158 | * @return int |
||
159 | 5 | */ |
|
160 | |||
161 | protected function _getOperator() : int |
||
162 | { |
||
163 | if ($this->_mode === 2) |
||
164 | { |
||
165 | return 1; |
||
166 | } |
||
167 | if ($this->_mode === 3) |
||
168 | { |
||
169 | return -1; |
||
170 | 5 | } |
|
171 | return random_int(0, 1) * 2 - 1; |
||
172 | 5 | } |
|
173 | |||
174 | 1 | /** |
|
175 | * create a task of two numbers between allowable range |
||
176 | 4 | * |
|
177 | * @since 2.0.0 |
||
178 | 1 | */ |
|
179 | |||
180 | 3 | protected function _create() : void |
|
181 | { |
||
182 | /* range */ |
||
183 | |||
184 | $min = $this->getMin(); |
||
185 | $max = $this->getMax(); |
||
186 | |||
187 | /* random numbers */ |
||
188 | |||
189 | 5 | $a = random_int($min + 1, $max); |
|
190 | $b = random_int($min, $a - 1); |
||
191 | |||
192 | /* operator */ |
||
193 | 5 | ||
194 | 5 | $c = $this->_getOperator(); |
|
195 | $operator = $this->_operatorArray[$c]; |
||
196 | |||
197 | /* solution and task */ |
||
198 | 5 | ||
199 | 5 | $this->_solution = $a + $b * $c; |
|
200 | $this->_task = $this->_language->get('_number')[$a] . ' ' . $this->_language->get($operator) . ' ' . $this->_language->get('_number')[$b]; |
||
201 | } |
||
202 | } |
||
203 |