Passed
Pull Request — master (#143)
by Arman
05:04 queued 02:36
created

RecaptchaAdapter::display()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
/**
4
 * Quantum PHP Framework
5
 *
6
 * An open source software development framework for PHP
7
 *
8
 * @package Quantum
9
 * @author Arman Ag. <[email protected]>
10
 * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org)
11
 * @link http://quantum.softberg.org/
12
 * @since 2.9.0
13
 */
14
15
namespace Quantum\Libraries\Captcha\Adapters;
16
17
use Quantum\Libraries\Curl\HttpClient;
18
19
/**
20
 * Class RecaptchaAdapter
21
 * @package Quantum\Libraries\Captcha\Adapters
22
 */
23
class RecaptchaAdapter extends BaseCaptcha
24
{
25
26
    const VERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify';
27
28
    const CLIENT_API = 'https://www.google.com/recaptcha/api.js';
29
30
    /**
31
     * @var string
32
     */
33
    protected $name = 'g-recaptcha';
34
35
    /**
36
     * @var string[]
37
     */
38
    protected $elementClasses = ['g-recaptcha'];
39
40
    /**
41
     * @var RecaptchaAdapter
42
     */
43
    private static $instance = null;
44
45
    /**
46
     * RecaptchaAdapter constructor
47
     * @param array $params
48
     * @param HttpClient $httpClient
49
     */
50
    private function __construct(array $params, HttpClient $httpClient)
51
    {
52
        $this->http = $httpClient;
53
54
        $this->secretKey = $params['secret_key'];
55
        $this->siteKey = $params['site_key'];
56
        $this->type = $params['type'] ?? null;
57
    }
58
59
    /**
60
     * Get Instance
61
     * @param array $params
62
     * @param HttpClient $httpClient
63
     * @return RecaptchaAdapter
64
     */
65
    public static function getInstance(array $params, HttpClient $httpClient): RecaptchaAdapter
66
    {
67
        if (self::$instance === null) {
68
            self::$instance = new self($params, $httpClient);
69
        }
70
71
        return self::$instance;
72
    }
73
74
    /**
75
     * @return void
76
     */
77
    public static function resetInstance(): void
78
    {
79
        self::$instance = null;
80
    }
81
82
}