Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
43 / 43 |
|
100.00% |
16 / 16 |
CRAP | |
100.00% |
1 / 1 |
legacy_wrapper | |
100.00% |
43 / 43 |
|
100.00% |
16 / 16 |
31 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
is_available | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
has_config | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
get_name | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
set_name | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
init | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
get_hidden_fields | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
validate | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
get_error | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
is_solved | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
reset | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
get_attempt_count | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
get_template | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
get_demo_template | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
garbage_collect | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
acp_page | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * |
4 | * This file is part of the phpBB Forum Software package. |
5 | * |
6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
8 | * |
9 | * For full copyright and license information, please see |
10 | * the docs/CREDITS.txt file. |
11 | * |
12 | */ |
13 | |
14 | namespace phpbb\captcha\plugins; |
15 | |
16 | class legacy_wrapper implements plugin_interface |
17 | { |
18 | /** @var object Legacy CAPTCHA instance, should implement functionality as required in phpBB 3.3 */ |
19 | private $legacy_captcha; |
20 | |
21 | /** @var string Last error */ |
22 | private string $last_error; |
23 | |
24 | /** |
25 | * Constructor for legacy CAPTCHA wrapper |
26 | * |
27 | * @param object $legacy_captcha |
28 | */ |
29 | public function __construct(object $legacy_captcha) |
30 | { |
31 | $this->legacy_captcha = $legacy_captcha; |
32 | } |
33 | |
34 | /** |
35 | * {@inheritDoc} |
36 | */ |
37 | public function is_available(): bool |
38 | { |
39 | if (method_exists($this->legacy_captcha, 'is_available')) |
40 | { |
41 | return $this->legacy_captcha->is_available(); |
42 | } |
43 | |
44 | return false; |
45 | } |
46 | |
47 | /** |
48 | * {@inheritDoc} |
49 | */ |
50 | public function has_config(): bool |
51 | { |
52 | if (method_exists($this->legacy_captcha, 'has_config')) |
53 | { |
54 | return $this->legacy_captcha->has_config(); |
55 | } |
56 | |
57 | return false; |
58 | } |
59 | |
60 | /** |
61 | * {@inheritDoc} |
62 | */ |
63 | public function get_name(): string |
64 | { |
65 | if (method_exists($this->legacy_captcha, 'get_name')) |
66 | { |
67 | return $this->legacy_captcha->get_name(); |
68 | } |
69 | |
70 | return ''; |
71 | } |
72 | |
73 | /** |
74 | * {@inheritDoc} |
75 | */ |
76 | public function set_name(string $name): void |
77 | { |
78 | if (method_exists($this->legacy_captcha, 'set_name')) |
79 | { |
80 | $this->legacy_captcha->set_name($name); |
81 | } |
82 | } |
83 | |
84 | /** |
85 | * {@inheritDoc} |
86 | */ |
87 | public function init(confirm_type $type): void |
88 | { |
89 | if (method_exists($this->legacy_captcha, 'init')) |
90 | { |
91 | $this->legacy_captcha->init($type->value); |
92 | } |
93 | } |
94 | |
95 | /** |
96 | * {@inheritDoc} |
97 | */ |
98 | public function get_hidden_fields(): array |
99 | { |
100 | if (method_exists($this->legacy_captcha, 'get_hidden_fields')) |
101 | { |
102 | return $this->legacy_captcha->get_hidden_fields(); |
103 | } |
104 | |
105 | return []; |
106 | } |
107 | |
108 | /** |
109 | * {@inheritDoc} |
110 | */ |
111 | public function validate(): bool |
112 | { |
113 | if (method_exists($this->legacy_captcha, 'validate')) |
114 | { |
115 | $error = $this->legacy_captcha->validate(); |
116 | if ($error) |
117 | { |
118 | $this->last_error = $error; |
119 | return false; |
120 | } |
121 | |
122 | return true; |
123 | } |
124 | |
125 | return false; |
126 | } |
127 | |
128 | /** |
129 | * {@inheritDoc} |
130 | */ |
131 | public function get_error(): string |
132 | { |
133 | return $this->last_error; |
134 | } |
135 | |
136 | /** |
137 | * {@inheritDoc} |
138 | */ |
139 | public function is_solved(): bool |
140 | { |
141 | if (method_exists($this->legacy_captcha, 'is_solved')) |
142 | { |
143 | return $this->legacy_captcha->is_solved(); |
144 | } |
145 | |
146 | return false; |
147 | } |
148 | |
149 | /** |
150 | * {@inheritDoc} |
151 | */ |
152 | public function reset(): void |
153 | { |
154 | if (method_exists($this->legacy_captcha, 'reset')) |
155 | { |
156 | $this->legacy_captcha->reset(); |
157 | } |
158 | } |
159 | |
160 | /** |
161 | * {@inheritDoc} |
162 | */ |
163 | public function get_attempt_count(): int |
164 | { |
165 | if (method_exists($this->legacy_captcha, 'get_attempt_count')) |
166 | { |
167 | return $this->legacy_captcha->get_attempt_count(); |
168 | } |
169 | |
170 | // Ensure this is deemed as too many attempts |
171 | return PHP_INT_MAX; |
172 | } |
173 | |
174 | /** |
175 | * {@inheritDoc} |
176 | */ |
177 | public function get_template(): string |
178 | { |
179 | if (method_exists($this->legacy_captcha, 'get_template')) |
180 | { |
181 | return $this->legacy_captcha->get_template(); |
182 | } |
183 | |
184 | return ''; |
185 | } |
186 | |
187 | /** |
188 | * {@inheritDoc} |
189 | */ |
190 | public function get_demo_template(): string |
191 | { |
192 | if (method_exists($this->legacy_captcha, 'get_demo_template')) |
193 | { |
194 | return $this->legacy_captcha->get_demo_template(0); |
195 | } |
196 | |
197 | return ''; |
198 | } |
199 | |
200 | /** |
201 | * {@inheritDoc} |
202 | */ |
203 | public function garbage_collect(confirm_type $confirm_type = confirm_type::UNDEFINED): void |
204 | { |
205 | if (method_exists($this->legacy_captcha, 'garbage_collect')) |
206 | { |
207 | $this->legacy_captcha->garbage_collect($confirm_type->value); |
208 | } |
209 | } |
210 | |
211 | /** |
212 | * {@inheritDoc} |
213 | */ |
214 | public function acp_page(mixed $id, mixed $module): void |
215 | { |
216 | if (method_exists($this->legacy_captcha, 'acp_page')) |
217 | { |
218 | $this->legacy_captcha->acp_page($id, $module); |
219 | } |
220 | } |
221 | } |