Passed
Push — master ( fa7991...10a1b7 )
by 世昌
02:08
created

ClosureTarget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRunnableTarget() 0 3 1
A invoke() 0 6 2
A __construct() 0 3 1
A isVaild() 0 3 1
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