Test Failed
Push — main ( 6435b1...db043e )
by Paul
16:23 queued 07:02
created

Captcha::configTurnstile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
ccs 0
cts 9
cp 0
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Modules;
4
5
use GeminiLabs\SiteReviews\Helper;
6
use GeminiLabs\SiteReviews\Modules\Html\Builder;
7
8
class Captcha
9
{
10
    public function actions(): array
11
    {
12
        return glsr()->filterArray('captcha/actions', [
13
            'submit-review',
14
        ]);
15
    }
16
17
    public function config(): array
18
    {
19
        if (!$this->isEnabled()) {
20
            return [];
21
        }
22
        $integration = (string) glsr_get_option('forms.captcha.integration');
23
        $className = Helper::buildClassName([$integration, 'validator'], 'Modules\Validator');
24
        if (!class_exists($className)) {
25
            return [];
26
        }
27
        return glsr($className)->config();
28
    }
29
30
    public function container(): string
31
    {
32
        if (!$this->isEnabled()) {
33
            return '';
34
        }
35
        return glsr(Builder::class)->div([
36
            'class' => 'glsr-captcha-holder',
37
        ]);
38
    }
39
40
    public function isEnabled(string $service = ''): bool
41
    {
42
        $integration = glsr_get_option('forms.captcha.integration');
43
        $usage = glsr_get_option('forms.captcha.usage');
44
        $isEnabled = 'all' === $usage || ('guest' === $usage && !is_user_logged_in());
45
        if (!empty($service)) {
46
            return $integration === $service && $isEnabled;
47
        }
48
        return !empty($integration) && $isEnabled;
49
    }
50
}
51