Passed
Push — master ( e5b474...40007f )
by wannanbigpig
02:47
created

Alipay::__callStatic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the wannanbigpig/alipay-sdk-php.
4
 *
5
 * (c) wannanbigpig <[email protected]>
6
 *
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace EasyAlipay;
12
13
use EasyAlipay\Kernel\Exceptions\ApplicationException;
14
use WannanBigPig\Supports\Str;
15
16
/**
17
 * Class Alipay
18
 *
19
 * @method static \EasyAlipay\Payment\Application payment(array $config = [])
20
 * @method static \EasyAlipay\Tripartite\Application tripartite(array $config = [])
21
 * @method static \EasyAlipay\MiniProgram\Application miniProgram(array $config = [])
22
 *
23
 * @author   liuml  <[email protected]>
24
 * @DateTime 2019-07-26  18:18
25
 */
26
class Alipay
27
{
28
    protected static $config = [];
29
30
    /**
31
     * make.
32
     *
33
     * @param string $name
34
     * @param array  $config
35
     *
36
     * @return mixed
37
     *
38
     * @throws \EasyAlipay\Kernel\Exceptions\ApplicationException
39
     */
40 126
    public static function make(string $name, array $config = [])
41
    {
42 126
        $namespace = Str::studly($name);
43 126
        $application = __NAMESPACE__."\\{$namespace}\\Application";
44
45 126
        if (class_exists($application)) {
46 126
            $config = array_replace_recursive(self::$config, $config);
47
48
            // Instantiation application
49 126
            return new $application($config);
50
        }
51 2
        throw new ApplicationException("Application [{$name}] does not exist");
52
    }
53
54
    /**
55
     * Dynamically pass methods to the application.
56
     *
57
     * @param $name
58
     * @param $arguments
59
     *
60
     * @return mixed
61
     *
62
     * @throws \EasyAlipay\Kernel\Exceptions\ApplicationException
63
     */
64 126
    public static function __callStatic($name, $arguments)
65
    {
66 126
        return self::make($name, ...$arguments);
67
    }
68
69
    /**
70
     * @static  initialize.
71
     *
72
     * @param array $config
73
     *
74
     * @return \EasyAlipay\Alipay
75
     */
76 2
    public static function initialize(array $config): self
77
    {
78 2
        self::$config = $config;
79
80 2
        return new static();
81
    }
82
83
    /**
84
     * __call.
85
     *
86
     * @param $name
87
     * @param $arguments
88
     *
89
     * @return mixed
90
     *
91
     * @throws \EasyAlipay\Kernel\Exceptions\ApplicationException
92
     */
93 2
    public function __call($name, $arguments)
94
    {
95 2
        return self::make($name, ...$arguments);
96
    }
97
}
98