Recaptcha3Type::getParent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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