Passed
Push — master ( fa7991...10a1b7 )
by 世昌
02:08
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 nebula\runnable\target\RunnableTarget;
5
6
/**
7
 * 可执行命令:文件类型
8
 * 
9
 */
10
class ClosureTarget extends RunnableTarget
11
{
12
13
    /**
14
     * 对象
15
     *
16
     * @var Closure
17
     */
18
    protected $closure;
19
    
20
    public function __construct(Closure $closure, array $parameter =[]) {
21
        $this->closure = $closure;
22
        $this->parameter = $parameter;
0 ignored issues
show
Bug Best Practice introduced by
The property parameter does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
    }
24
25
    public function getRunnableTarget()
26
    {
27
        return $this->closure;
28
    }
29
30
31
    /**
32
     * 是否可执行
33
     *
34
     * @return boolean
35
     */
36
    public function isVaild():bool
37
    {
38
        return true; 
39
    }
40
41
    /**
42
     * 执行代码
43
     *
44
     * @param array $args
45
     * @return mixed
46
     */
47
    public function invoke(array $parameter)
48
    {
49
        if (count($parameter) == 0) {
50
            $parameter = $this->getParameter();
51
        }
52
        return forward_static_call_array($this->closure, $parameter);
53
    }
54
}
55