Passed
Push — master ( f2e76c...2ddbad )
by 世昌
03:02
created

ClosureTarget::isVaild()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\runnable\target;
3
4
use Closure;
5
use nebula\runnable\target\RunnableTarget;
6
7
/**
8
 * 可执行命令:文件类型
9
 * 
10
 */
11
class ClosureTarget extends RunnableTarget
12
{
13
14
    /**
15
     * 对象
16
     *
17
     * @var Closure
18
     */
19
    protected $closure;
20
    
21
    public function __construct(Closure $closure, array $parameter =[]) {
22
        $this->closure = $closure;
23
        $this->parameter = $parameter;
24
        $this->name = 'Closure object()';
25
    }
26
27
    public function getRunnableTarget()
28
    {
29
        return $this->closure;
30
    }
31
32
33
    /**
34
     * 是否可执行
35
     *
36
     * @return boolean
37
     */
38
    public function isVaild():bool
39
    {
40
        return true; 
41
    }
42
43
    /**
44
     * 执行代码
45
     *
46
     * @param array $args
47
     * @return mixed
48
     */
49
    public function apply(array $parameter)
50
    {
51
        if (count($parameter) == 0) {
52
            $parameter = $this->getParameter();
53
        }
54
        return forward_static_call_array($this->closure, $parameter);
55
    }
56
}
57