Passed
Pull Request — master (#190)
by Arman
04:27
created

Captcha::getAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

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
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.5
13
 */
14
15
namespace Quantum\Libraries\Captcha;
16
17
use Quantum\Libraries\Captcha\Exceptions\CaptchaException;
18
use Quantum\Libraries\Captcha\Contracts\CaptchaInterface;
19
use Quantum\Exceptions\BaseException;
20
21
/**
22
 * Class Captcha
23
 * @package Quantum\Libraries\Captcha
24
 * @method string getName()
25
 * @method string|null getType()
26
 * @method CaptchaInterface setType(string $type)
27
 * @method mixed addToForm(string $formIdentifier)
28
 * @method mixed verify(string $response)
29
 * @method string|null getErrorMessage()
30
 */
31
class Captcha
32
{
33
34
    /**
35
     * HCaptcha adapter
36
     */
37
    const HCAPTCHA = 'hcaptcha';
38
39
    /**
40
     * ReCaptcha adapter
41
     */
42
    const RECAPTCHA = 'recaptcha';
43
44
    /**
45
     * @var CaptchaInterface
46
     */
47
    private $adapter;
48
49
    /**
50
     * @param CaptchaInterface $adapter
51
     */
52
    public function __construct(CaptchaInterface $adapter)
53
    {
54
        $this->adapter = $adapter;
55
    }
56
57
    /**
58
     * @return CaptchaInterface
59
     */
60
    public function getAdapter(): CaptchaInterface
61
    {
62
        return $this->adapter;
63
    }
64
65
    /**
66
     * @param string $method
67
     * @param array|null $arguments
68
     * @return mixed
69
     * @throws BaseException
70
     */
71
    public function __call(string $method, ?array $arguments)
72
    {
73
        if (!method_exists($this->adapter, $method)) {
74
            throw CaptchaException::methodNotSupported($method, get_class($this->adapter));
75
        }
76
77
        return $this->adapter->$method(...$arguments);
78
    }
79
}