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

HcaptchaAdapter::resetInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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 HcaptchaAdapter
21
 * @package Quantum\Libraries\Captcha\Adapters
22
 */
23
class HcaptchaAdapter extends BaseCaptcha
24
{
25
26
    const VERIFY_URL = 'https://hcaptcha.com/siteverify';
27
28
    const CLIENT_API = 'https://hcaptcha.com/1/api.js?onload=onLoadCallback&recaptchacompat=off';
29
30
    /**
31
     * @var string
32
     */
33
    protected $name = 'h-captcha';
34
35
    /**
36
     * @var string[]
37
     */
38
    protected $elementClasses = ['h-captcha'];
39
40
    /**
41
     * @var HcaptchaAdapter
42
     */
43
    private static $instance = null;
44
45
    /**
46
     * Hcaptcha 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 HcaptchaAdapter
64
     */
65
    public static function getInstance(array $params, HttpClient $httpClient): HcaptchaAdapter
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
}