Recaptcha3Type   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 39
ccs 17
cts 17
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A configureOptions() 0 7 1
A buildView() 0 6 1
A getBlockPrefix() 0 3 1
A getParent() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Karser\Recaptcha3Bundle\Form;
4
5
use Symfony\Component\Form\AbstractType;
6
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
7
use Symfony\Component\Form\FormInterface;
8
use Symfony\Component\Form\FormView;
9
use Symfony\Component\OptionsResolver\OptionsResolver;
10
11
final class Recaptcha3Type extends AbstractType
12
{
13
    /** @var string */
14
    private $siteKey;
15
16
    /** @var bool */
17
    private $enabled;
18
19 6
    public function __construct(string $siteKey, bool $enabled)
20
    {
21 6
        $this->siteKey = $siteKey;
22 6
        $this->enabled = $enabled;
23 6
    }
24
25 3
    public function buildView(FormView $view, FormInterface $form, array $options): void
26
    {
27 3
        $view->vars['site_key'] = $this->siteKey;
28 3
        $view->vars['enabled'] = $this->enabled;
29 3
        $view->vars['action_name'] = $options['action_name'];
30 3
        $view->vars['script_nonce_csp'] = $options['script_nonce_csp'] ?? '';
31
    }
32 6
33
    public function getParent(): string
34 6
    {
35
        return HiddenType::class;
36
    }
37 3
38
    public function getBlockPrefix(): string
39 3
    {
40
        return 'karser_recaptcha3';
41
    }
42 6
43
    public function configureOptions(OptionsResolver $resolver): void
44 6
    {
45 6
        $resolver->setDefaults([
46
            'mapped' => false,
47
            'site_key' => null,
48
            'action_name' => 'homepage',
49 6
            'script_nonce_csp' => '',
50
        ]);
51
    }
52
}
53