Passed
Push — main ( 58ef3e...be0a65 )
by Michiel
07:16
created

ConditionBase::createEquals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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\System\Condition;
22
23
use IteratorAggregate;
24
use Phing\Exception\BuildException;
25
use Phing\Parser\CustomChildCreator;
26
use Phing\Project;
27
use Phing\ProjectComponent;
28
use Phing\Task\System\AvailableTask;
29
use Phing\Task\System\Pdo\PDOSQLExecTask;
30
31
/**
32
 * Abstract baseclass for the <condition> task as well as several
33
 * conditions - ensures that the types of conditions inside the task
34
 * and the "container" conditions are in sync.
35
 *
36
 * @author    Hans Lellelid <[email protected]>
37
 * @author    Andreas Aderhold <[email protected]>
38
 * @copyright 2001,2002 THYRELL. All rights reserved
39
 */
40
abstract class ConditionBase extends ProjectComponent implements IteratorAggregate, CustomChildCreator
41
{
42
    public $conditions = []; // needs to be public for "inner" class access
43
44
    /**
45
     * @var string
46
     */
47
    private $taskName = 'condition';
48
49 233
    public function __construct($taskName = 'component')
50
    {
51 233
        parent::__construct();
52 233
        $this->taskName = $taskName;
53 233
    }
54
55
    /**
56
     * Sets the name to use in logging messages.
57
     *
58
     * @param string $name The name to use in logging messages.
59
     *                     Should not be <code>null</code>.
60
     */
61
    public function setTaskName($name)
62
    {
63
        $this->taskName = $name;
64
    }
65
66
    /**
67
     * Returns the name to use in logging messages.
68
     *
69
     * @return string the name to use in logging messages
70
     */
71 5
    public function getTaskName()
72
    {
73 5
        return $this->taskName;
74
    }
75
76
    /**
77
     * @return int
78
     */
79 231
    public function countConditions()
80
    {
81 231
        return count($this->conditions);
82
    }
83
84
    /**
85
     * Required for \IteratorAggregate.
86
     */
87 40
    public function getIterator(): ConditionEnumeration
88
    {
89 40
        return new ConditionEnumeration($this);
90
    }
91
92
    /**
93
     * @return Condition[]
94
     */
95 200
    public function getConditions()
96
    {
97 200
        return $this->conditions;
98
    }
99
100 4
    public function addAvailable(AvailableTask $a)
101
    {
102 4
        $this->conditions[] = $a;
103 4
    }
104
105
    /**
106
     * @return NotCondition
107
     */
108 5
    public function createNot()
109
    {
110 5
        $num = array_push($this->conditions, new NotCondition());
111
112 5
        return $this->conditions[$num - 1];
113
    }
114
115
    /**
116
     * @return AndCondition
117
     */
118 2
    public function createAnd()
119
    {
120 2
        $num = array_push($this->conditions, new AndCondition());
121
122 2
        return $this->conditions[$num - 1];
123
    }
124
125
    /**
126
     * @return OrCondition
127
     */
128 1
    public function createOr()
129
    {
130 1
        $num = array_push($this->conditions, new OrCondition());
131
132 1
        return $this->conditions[$num - 1];
133
    }
134
135
    /**
136
     * @return XorCondition
137
     */
138 7
    public function createXor()
139
    {
140 7
        $num = array_push($this->conditions, new XorCondition());
141
142 7
        return $this->conditions[$num - 1];
143
    }
144
145
    /**
146
     * @return EqualsCondition
147
     */
148 12
    public function createEquals()
149
    {
150 12
        $num = array_push($this->conditions, new EqualsCondition());
151
152 12
        return $this->conditions[$num - 1];
153
    }
154
155
    /**
156
     * @return OsCondition
157
     */
158 183
    public function createOs()
159
    {
160 183
        $num = array_push($this->conditions, new OsCondition());
161
162 183
        return $this->conditions[$num - 1];
163
    }
164
165
    /**
166
     * @return IsFalseCondition
167
     */
168
    public function createIsFalse()
169
    {
170
        $num = array_push($this->conditions, new IsFalseCondition());
171
172
        return $this->conditions[$num - 1];
173
    }
174
175
    /**
176
     * @return IsTrueCondition
177
     */
178 7
    public function createIsTrue()
179
    {
180 7
        $num = array_push($this->conditions, new IsTrueCondition());
181
182 7
        return $this->conditions[$num - 1];
183
    }
184
185
    /**
186
     * @return IsPropertyFalseCondition
187
     */
188 2
    public function createIsPropertyFalse()
189
    {
190 2
        $num = array_push($this->conditions, new IsPropertyFalseCondition());
191
192 2
        return $this->conditions[$num - 1];
193
    }
194
195
    /**
196
     * @return IsPropertyTrueCondition
197
     */
198 2
    public function createIsPropertyTrue()
199
    {
200 2
        $num = array_push($this->conditions, new IsPropertyTrueCondition());
201
202 2
        return $this->conditions[$num - 1];
203
    }
204
205
    /**
206
     * @return ContainsCondition
207
     */
208 1
    public function createContains()
209
    {
210 1
        $num = array_push($this->conditions, new ContainsCondition());
211
212 1
        return $this->conditions[$num - 1];
213
    }
214
215
    /**
216
     * @return IsSetCondition
217
     */
218
    public function createIsSet()
219
    {
220
        $num = array_push($this->conditions, new IsSetCondition());
221
222
        return $this->conditions[$num - 1];
223
    }
224
225
    /**
226
     * @return ReferenceExistsCondition
227
     */
228 1
    public function createReferenceExists()
229
    {
230 1
        $num = array_push($this->conditions, new ReferenceExistsCondition());
231
232 1
        return $this->conditions[$num - 1];
233
    }
234
235
    public function createVersionCompare()
236
    {
237
        $num = array_push($this->conditions, new VersionCompareCondition());
238
239
        return $this->conditions[$num - 1];
240
    }
241
242
    public function createHttp()
243
    {
244
        $num = array_push($this->conditions, new HttpCondition());
245
246
        return $this->conditions[$num - 1];
247
    }
248
249 1
    public function createPhingVersion()
250
    {
251 1
        $num = array_push($this->conditions, new PhingVersion());
252
253 1
        return $this->conditions[$num - 1];
254
    }
255
256 5
    public function createHasFreeSpace()
257
    {
258 5
        $num = array_push($this->conditions, new HasFreeSpaceCondition());
259
260 5
        return $this->conditions[$num - 1];
261
    }
262
263 3
    public function createFilesMatch()
264
    {
265 3
        $num = array_push($this->conditions, new FilesMatch());
266
267 3
        return $this->conditions[$num - 1];
268
    }
269
270 1
    public function createSocket()
271
    {
272 1
        $num = array_push($this->conditions, new SocketCondition());
273
274 1
        return $this->conditions[$num - 1];
275
    }
276
277 2
    public function createIsFailure()
278
    {
279 2
        $num = array_push($this->conditions, new IsFailure());
280
281 2
        return $this->conditions[$num - 1];
282
    }
283
284 6
    public function createIsFileSelected()
285
    {
286 6
        $num = array_push($this->conditions, new IsFileSelected());
287
288 6
        return $this->conditions[$num - 1];
289
    }
290
291 1
    public function createMatches()
292
    {
293 1
        $num = array_push($this->conditions, new Matches());
294
295 1
        return $this->conditions[$num - 1];
296
    }
297
298 6
    public function createPdoSqlExec()
299
    {
300 6
        $num = array_push($this->conditions, new PDOSQLExecTask());
301
302 6
        return $this->conditions[$num - 1];
303
    }
304
305
    /**
306
     * @param string $elementName
307
     *
308
     * @throws BuildException
309
     *
310
     * @return Condition
311
     */
312 1
    public function customChildCreator($elementName, Project $project)
313
    {
314 1
        $condition = $project->createCondition($elementName);
315 1
        $num = array_push($this->conditions, $condition);
316
317 1
        return $this->conditions[$num - 1];
318
    }
319
}
320