Passed
Push — main ( e5a85d...619edc )
by Michiel
07:04
created

ZsdtPackTask   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 17
eloc 32
dl 0
loc 158
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 3 1
A setLint() 0 3 1
A setPhpbin() 0 3 1
A setPackage() 0 3 1
B validate() 0 34 10
A setScripts() 0 3 1
A setSource() 0 3 1
A setOutput() 0 3 1
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Task\Ext\ZendServerDeploymentTool;
22
23
use Phing\Exception\BuildException;
24
25
/**
26
 * Class ZendServerDeploymentToolTask
27
 *
28
 * @author  Siad Ardroumli <[email protected]>
29
 * @package phing.tasks.ext.zendserverdevelopmenttools
30
 */
31
class ZsdtPackTask extends ZsdtBaseTask
32
{
33
    /**
34
     * @var string $package
35
     */
36
    private $package;
37
38
    /**
39
     * @var string $source
40
     */
41
    private $source;
42
43
    /**
44
     * @var string $scripts
45
     */
46
    private $scripts;
47
48
    /**
49
     * @var string $output
50
     */
51
    private $output;
52
53
    /**
54
     * @var string $phpbin
55
     */
56
    private $phpbin;
57
58
    /**
59
     * @var bool $lint
60
     */
61
    private $lint = false;
62
63
    /**
64
     * A directory containing the data and the script directories, in addition to the package descriptor file.
65
     *
66
     * @param string $package
67
     *
68
     * @return void
69
     */
70
    public function setPackage($package)
71
    {
72
        $this->package = escapeshellarg($package);
73
    }
74
75
    /**
76
     * Performs a PHP lint test on the deployment scripts before creating the package.
77
     *
78
     * @param boolean $lint
79
     *
80
     * @return void
81
     */
82
    public function setLint($lint)
83
    {
84
        $this->lint = $lint;
85
    }
86
87
    /**
88
     * The directory in which the package is created.
89
     * The package name will be created as "<app-name>-<app-version>.zpk".
90
     *
91
     * @param string $output
92
     *
93
     * @return void
94
     */
95
    public function setOutput($output)
96
    {
97
        $this->output = escapeshellarg($output);
98
    }
99
100
    /**
101
     * The PHP executable to use for lint.
102
     *
103
     * @param string $phpbin
104
     *
105
     * @return void
106
     */
107
    public function setPhpbin($phpbin)
108
    {
109
        $this->phpbin = escapeshellarg($phpbin);
110
    }
111
112
    /**
113
     * The directory which contains the package deployment scripts.
114
     * The Deployment Tool will search this directory for the expected files and then packs them.
115
     *
116
     * @param string $scripts
117
     *
118
     * @return void
119
     */
120
    public function setScripts($scripts)
121
    {
122
        $this->scripts = escapeshellarg($scripts);
123
    }
124
125
    /**
126
     * The directory that contains the application resources (PHP sources, JavaScript, etc.).
127
     * The directory's internal structure must match the necessary structure for the application to be functional.
128
     *
129
     * @param string $source
130
     *
131
     * @return void
132
     */
133
    public function setSource($source)
134
    {
135
        $this->source = escapeshellarg($source);
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     *
141
     * @return void
142
     */
143
    public function init()
144
    {
145
        $this->action = 'pack';
146
    }
147
148
    /**
149
     * {@inheritdoc}
150
     *
151
     * @return void
152
     *
153
     * @throws BuildException
154
     */
155
    protected function validate()
156
    {
157
        if ($this->descriptor === null || $this->scripts === null || $this->package === null) {
158
            throw new BuildException(
159
                'The deployment tool needs at least the project descriptor, '
160
                . 'the scripts folder and package folder to be set.'
161
            );
162
        }
163
164
        if ($this->lint !== false && $this->phpbin === null) {
165
            throw new BuildException('You set the lint option but not the path to the php executable.');
166
        }
167
168
        parent::validate();
169
170
        if ($this->lint !== false) {
171
            $this->arguments .= '--lint ';
172
        }
173
174
        if ($this->source !== null) {
175
            $this->arguments .= "--src-dir=$this->source ";
176
        }
177
178
        if ($this->output !== null) {
179
            $this->arguments .= "--output-dir=$this->output ";
180
        }
181
182
        if ($this->phpbin !== null) {
183
            $this->arguments .= "--php-exe=$this->phpbin ";
184
        }
185
186
        $this->arguments .= "--scripts-dir=$this->scripts ";
187
        $this->arguments .= "--package-descriptor=$this->descriptor ";
188
        $this->arguments .= $this->package;
189
    }
190
}
191