GoogleRecaptcha::setManager()   A
last analyzed

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 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ByTIC\GoogleRecaptcha\Utility;
4
5
use ByTIC\GoogleRecaptcha\Config\Config;
6
use ByTIC\GoogleRecaptcha\RecaptchaManager;
7
8
/**
9
 * Class GoogleRecaptcha
10
 * @package ByTIC\GoogleRecaptcha\Utility
11
 */
12
class GoogleRecaptcha
13
{
14
    /**
15
     * @var null|RecaptchaManager
16
     */
17
    protected static $manager = null;
18
19
    protected static $config = null;
20
21
    /**
22
     * @param $method
23
     * @param $arguments
24
     * @return mixed
25
     */
26
    public static function __callStatic($method, $arguments)
27
    {
28
        return call_user_func_array([static::getManager(), $method], $arguments);
29
    }
30
31
    /**
32
     * @return null|RecaptchaManager
33
     */
34
    public static function getManager()
35
    {
36
        if (self::$manager === null) {
37
            static::initManager();
38
        }
39
40
        return self::$manager;
41
    }
42
43
    protected static function initManager()
44
    {
45
        self::setManager(RecaptchaManager::fromConfig(static::getConfig()));
46
    }
47
48
49
    /**
50
     * @param RecaptchaManager $manager
51
     */
52
    public static function setManager($manager)
53
    {
54
        self::$manager = $manager;
55
    }
56
57
    /**
58
     * @return Config
59
     */
60
    protected static function getConfig()
61
    {
62
        if (self::$config === null) {
63
            self::$config = Config::autoInit();
64
        }
65
66
        return self::$config;
67
    }
68
69
    /**
70
     * @param $config
71
     */
72
    public static function setConfig($config)
73
    {
74
        self::$config = $config;
75
    }
76
}
77