Completed
Push — master ( f77f61...4f79b1 )
by wannanbigpig
02:51 queued 11s
created

Alipay::make()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
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
 *
21
 * @author   liuml  <[email protected]>
22
 * @DateTime 2019-07-26  18:18
23
 */
24
class Alipay
25
{
26
    /**
27
     * make.
28
     *
29
     * @param string $name
30
     * @param array  $config
31
     *
32
     * @return mixed
33
     *
34
     * @throws \EasyAlipay\Kernel\Exceptions\ApplicationException
35
     */
36 44
    public static function make(string $name, array $config)
37
    {
38 44
        $namespace = Str::studly($name);
39 44
        $application = __NAMESPACE__."\\{$namespace}\\Application";
40
41 44
        if (class_exists($application)) {
42
            // Instantiation application
43 42
            return new $application($config);
44
        }
45 2
        throw new ApplicationException("Application [{$name}] does not exist");
46
    }
47
48
    /**
49
     * Dynamically pass methods to the application.
50
     *
51
     * @param $name
52
     * @param $arguments
53
     *
54
     * @return mixed
55
     *
56
     * @throws \EasyAlipay\Kernel\Exceptions\ApplicationException
57
     */
58 44
    public static function __callStatic($name, $arguments)
59
    {
60 44
        return self::make($name, ...$arguments);
61
    }
62
}
63