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

FileTarget::getRunnableTarget()   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 FileTarget extends RunnableTarget
11
{
12
13
    /**
14
     * 需要的文件
15
     *
16
     * @var string|null
17
     */
18
    protected $requireFile=null;
19
    
20
    public function __construct(string $path, array $parameter =[]) {
21
        $this->setRequireFile($path);
22
        $this->setParameter($parameter);
23
    }
24
25
    public function getRunnableTarget()
26
    {
27
        return null;
28
    }
29
30
    /**
31
     * Get 需要的文件
32
     *
33
     * @return  string|null
34
     */
35
    public function getRequireFile()
36
    {
37
        return $this->requireFile;
38
    }
39
40
    /**
41
     * Set 需要的文件
42
     *
43
     * @param  string|null  $requireFile  需要的文件
44
     *
45
     * @return  self
46
     */
47
    public function setRequireFile($requireFile)
48
    {
49
        $this->requireFile = $requireFile;
50
        $this->name ='@'.$requireFile;
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
51
        return $this;
52
    }
53
54
    /**
55
     * 是否可执行
56
     *
57
     * @return boolean
58
     */
59
    public function isVaild():bool
60
    {
61
        return $this->requireFile !== null && file_exists($this->requireFile);
62
    }
63
64
    /**
65
     * 执行代码
66
     *
67
     * @param array $args
68
     * @return mixed
69
     */
70
    public function invoke(array $args)
71
    {
72
        if (count($args) == 0) {
73
            $args = $runnable->getParameter();
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $runnable seems to be never defined.
Loading history...
74
        }
75
        array_unshift($args, $this->requireFile);
76
        $_SERVER['argv']=$args;
77
        $_SERVER['args']=count($args);
78
        return include $requireFile;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $requireFile seems to be never defined.
Loading history...
79
    }
80
}
81