RecaptchaExtension::getRecapcthaPublicKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Acelaya\Website\Template\Extension;
5
6
use League\Plates\Engine;
7
use League\Plates\Extension\ExtensionInterface;
8
9
class RecaptchaExtension implements ExtensionInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $config;
15
16
    public function __construct(array $config)
17
    {
18
        $this->config = $config;
19
    }
20
21
    public function register(Engine $engine)
22
    {
23
        $engine->registerFunction('recaptcha_public', [$this, 'getRecapcthaPublicKey']);
24
        $engine->registerFunction('recaptcha_input', [$this, 'renderInput']);
25
    }
26
27
    public function getRecapcthaPublicKey(): string
28
    {
29
        return $this->config['public_key'];
30
    }
31
32
    public function renderInput(string $lang = 'en'): string
33
    {
34
        return '
35
            <script
36
            src="https://www.google.com/recaptcha/api.js?hl=' . $lang . '">
37
            </script>
38
            <div class="g-recaptcha"
39
                 data-sitekey="' . $this->getRecapcthaPublicKey() . '"
40
                 data-callback="recaptchaCallaback">
41
            </div>
42
        ';
43
    }
44
}
45