ExecuteNode   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 88
ccs 0
cts 28
cp 0
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setDirectory() 0 3 1
A getDirectory() 0 3 1
A __toString() 0 19 4
A getScript() 0 3 1
A setScript() 0 3 1
1
<?php
2
3
/**
4
 * AppserverIo\Provisioning\Api\Node\ExecuteNode
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2018 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/appserver-io/provisioning
18
 * @link      http://www.appserver.io
19
 */
20
21
namespace AppserverIo\Provisioning\Api\Node;
22
23
use AppserverIo\Description\Annotations as DI;
24
25
/**
26
 * DTO to transfer information about a script that has to be executed.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2018 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/appserver-io/provisioning
32
 * @link      http://www.appserver.io
33
 */
34
class ExecuteNode extends AbstractArgsNode
35
{
36
37
    /**
38
     * The script to be executed.
39
     *
40
     * @var string
41
     * @DI\Mapping(nodeType="string")
42
     */
43
    protected $script;
44
45
    /**
46
     * The directory to execute the script from.
47
     *
48
     * @var string
49
     * @DI\Mapping(nodeType="string")
50
     */
51
    protected $directory;
52
53
    /**
54
     * Set's the script to be executed.
55
     *
56
     * @param string $script The script
57
     *
58
     * @return void
59
     */
60
    public function setScript($script)
61
    {
62
        $this->script = $script;
63
    }
64
65
    /**
66
     * Return's the script to be executed.
67
     *
68
     * @return string The script
69
     */
70
    public function getScript()
71
    {
72
        return $this->script;
73
    }
74
75
    /**
76
     * Set's the directory to execute the script from.
77
     *
78
     * @param string $directory The directory
79
     *
80
     * @return void
81
     */
82
    public function setDirectory($directory)
83
    {
84
        $this->directory = $directory;
85
    }
86
87
    /**
88
     * Return's the directory to execute the script from.
89
     *
90
     * @return string The directory
91
     */
92
    public function getDirectory()
93
    {
94
        return $this->directory;
95
    }
96
97
    /**
98
     * Prepares the command to be excuted based on the script and
99
     * the arguments.
100
     *
101
     * @return string The command to execute
102
     */
103
    public function __toString()
104
    {
105
106
        // initialize the command with the script name
107
        $command = $this->script;
108
109
        // append the arguments
110
        /** @var \AppserverIo\Provisioning\Api\Node\ArgNode $arg */
111
        foreach ($this->getArgs() as $arg) {
112
            if ($name = $arg->getName()) {
113
                $command .=  ' ' . $name;
114
            }
115
            if ($value = $arg->castToType()) {
116
                $command .= ' ' . $value;
117
            }
118
        }
119
120
        // return the initialized command
121
        return $command;
122
    }
123
}
124