Passed
Push — master ( e59daf...2d0497 )
by Siad
40:41
created

BindTargets::setOnMissingExtensionPoint()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 10
ccs 3
cts 4
cp 0.75
crap 2.0625
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
/**
21
 * Simple task which bind some targets to some defined extension point
22
 *
23
 * @author    Siad Ardroumli <[email protected]>
24
 * @package   phing.tasks.system
25
 */
26
class BindTargets extends Task
27
{
28
    /** @var string $extensionPoint */
29
    private $extensionPoint;
30
31
    /** @var Target[] $targets */
32
    private $targets = [];
33
34
    private $onMissingExtensionPoint = 'fail';
35
36 1
    public function setExtensionPoint(string $extensionPoint)
37
    {
38 1
        $this->extensionPoint = $extensionPoint;
39 1
    }
40
41 1
    public function setOnMissingExtensionPoint(string $onMissingExtensionPoint)
42
    {
43 1
        if (!in_array($onMissingExtensionPoint, ['fail', 'warn', 'ignore'], true)) {
44
            throw new BuildException("Invalid onMissingExtensionPoint: " . $onMissingExtensionPoint);
45
        }
46 1
        $this->onMissingExtensionPoint = $onMissingExtensionPoint;
47 1
    }
48
49 1
    public function setTargets(string $target)
50
    {
51 1
        $this->targets = array_values(array_filter(array_map('trim', explode(',', $target))));
52 1
    }
53
54 1
    public function main()
55
    {
56 1
        if ($this->extensionPoint === null) {
57
            throw new BuildException('extensionPoint required', $this->getLocation());
58
        }
59
60 1
        if ($this->getOwningTarget() === null || "" !== $this->getOwningTarget()->getName()) {
61
            throw new BuildException('bindtargets only allowed as a top-level task');
62
        }
63
64
        /** @var PhingXMLContext $ctx */
65 1
        $ctx = $this->getProject()->getReference(ProjectConfigurator::PARSING_CONTEXT_REFERENCE);
66
67 1
        foreach ($this->targets as $target) {
68 1
            $ctx->addExtensionPoint([$this->extensionPoint, $target, $this->onMissingExtensionPoint, null]);
69
        }
70 1
    }
71
}
72