Facade::createFacade()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
nc 6
nop 2
dl 0
loc 11
ccs 7
cts 8
cp 0.875
crap 4.0312
rs 9.2
c 1
b 0
f 0
1
<?php
2
/**
3
 * Created by rozbo at 2017/3/17 上午11:43
4
 */
5
6
namespace puck;
7
8
class Facade
9
{
10
11
    protected static $bind=[];
12
13
    /**
14
     * 绑定类的静态代理
15
     * @static
16
     * @access public
17
     * @param string    $name    代理名
18
     * @param string    $class   实际类名
19
     * @return object
20
     */
21 1
    public static function bind($name, $class=null)
22
    {
23 1
        if (is_array($name)) {
24
            self::$bind=array_merge(self::$bind, $name);
25
        } else {
26 1
            self::$bind[$name]=$class;
27
        }
28 1
    }
29
30
    /**
31
     * 带参数实例化当前Facade类
32
     * @access public
33
     * @return object
34
     */
35
    public static function instance(...$args) {
36
        return self::createFacade('', $args);
37
    }
38
39
    /**
40
     * 创建Facade实例
41
     * @static
42
     * @access protected
43
     * @param string    $class    类名或标识
44
     * @param array     $args     变量
45
     * @return object
46
     */
47 1
    protected static function createFacade($class='', $args=[])
48
    {
49 1
        $class=$class ?: static::class;
50 1
        $facadeClass=static::getFacadeClass();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $facadeClass is correct as static::getFacadeClass() (which targets puck\Facade::getFacadeClass()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51 1
        if ($facadeClass) {
52
            $class=$facadeClass;
53 1
        } elseif (isset(self::$bind[$class])) {
54 1
            $class=self::$bind[$class];
55
        }
56 1
        return Container::getInstance()->make($class, $args);
57
    }
58
59 1
    protected static function getFacadeClass()
60 1
    {}
61
62
    /**
63
     * 指定某个Facade类进行实例化
64
     * @access public
65
     * @param string    $class    类名或者标识
66
     * @param array     $args     变量
67
     * @return object
68
     */
69 1
    public static function make($class, $args=[])
70
    {
71 1
        return self::createFacade($class, $args);
72
    }
73
74
    // 调用实际类的方法
75
    public static function __callStatic($method, $params)
76
    {
77
        return call_user_func_array([static::createFacade(), $method], $params);
78
    }
79
}