Completed
Push — master ( 81f41e...758549 )
by Siad
12:39
created

PhingCallTask::main()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.3731

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 5
nop 0
dl 0
loc 21
ccs 10
cts 14
cp 0.7143
crap 4.3731
rs 9.8333
c 0
b 0
f 0
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
 * Call another target in the same project.
22
 *
23
 * <samp>
24
 *    <target name="foo">
25
 *      <phingcall target="bar">
26
 *        <property name="property1" value="aaaaa" />
27
 *        <property name="foo" value="baz" />
28
 *       </phingcall>
29
 *    </target>
30
 *
31
 *    <target name="bar" depends="init">
32
 *      <echo message="prop is ${property1} ${foo}" />
33
 *    </target>
34
 * </samp>
35
 *
36
 * This only works as expected if neither property1 nor foo are defined in the project itself.
37
 *
38
 * @author    Andreas Aderhold <[email protected]>
39
 * @copyright 2001,2002 THYRELL. All rights reserved
40
 * @package   phing.tasks.system
41
 */
42
class PhingCallTask extends Task
43
{
44
45
    /**
46
     * The called Phing task.
47
     *
48
     * @var PhingTask
49
     */
50
    private $callee;
51
52
    /**
53
     * The target to call.
54
     *
55
     * @var string
56
     */
57
    private $subTarget;
58
59
    /**
60
     * Whether to inherit all properties from current project.
61
     *
62
     * @var boolean
63
     */
64
    private $inheritAll = true;
65
66
    /**
67
     * Whether to inherit refs from current project.
68
     *
69
     * @var boolean
70
     */
71
    private $inheritRefs = false;
72
73
    /**
74
     *  If true, pass all properties to the new Phing project.
75
     *  Defaults to true. Future use.
76
     *
77
     * @param boolean new value
78
     */
79 8
    public function setInheritAll($inherit)
80
    {
81 8
        $this->inheritAll = (bool) $inherit;
82 8
    }
83
84
    /**
85
     *  If true, pass all references to the new Phing project.
86
     *  Defaults to false. Future use.
87
     *
88
     * @param boolean new value
89
     */
90 8
    public function setInheritRefs($inheritRefs)
91
    {
92 8
        $this->inheritRefs = (bool) $inheritRefs;
93 8
    }
94
95
    /**
96
     * Alias for createProperty
97
     *
98
     * @see createProperty()
99
     */
100
    public function createParam()
101
    {
102
        if ($this->callee === null) {
103
            $this->init();
104
        }
105
106
        return $this->callee->createProperty();
0 ignored issues
show
Bug introduced by
The method createProperty() does not exist on Task. It seems like you code against a sub-type of Task such as PhingCallTask or ForeachTask or PhingTask or Phing\Tasks\Ext\AbstractLiquibaseTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
        return $this->callee->/** @scrutinizer ignore-call */ createProperty();
Loading history...
107
    }
108
109
    /**
110
     * Property to pass to the invoked target.
111
     */
112 7
    public function createProperty()
113
    {
114 7
        if ($this->callee === null) {
115
            $this->init();
116
        }
117
118 7
        return $this->callee->createProperty();
119
    }
120
121
    /**
122
     * Target to execute, required.
123
     *
124
     * @param string $target
125
     */
126 9
    public function setTarget(string $target): void
127
    {
128 9
        if ($this->callee === null) {
129
            $this->init();
130
        }
131 9
        $this->callee->setTarget($target);
0 ignored issues
show
Bug introduced by
The method setTarget() does not exist on Task. It seems like you code against a sub-type of Task such as PhingCallTask or ForeachTask or PhingTask or RunTargetTask or SymlinkTask or S3GetTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

131
        $this->callee->/** @scrutinizer ignore-call */ 
132
                       setTarget($target);
Loading history...
132 9
        $this->subTarget = $target;
133 9
    }
134
135
    /**
136
     * Reference element identifying a data type to carry
137
     * over to the invoked target.
138
     *
139
     * @param PhingReference $r the specified `PhingReference`.
140
     */
141 1
    public function addReference(PhingReference $r)
142
    {
143 1
        if ($this->callee === null) {
144
            $this->init();
145
        }
146 1
        $this->callee->addReference($r);
0 ignored issues
show
Bug introduced by
The method addReference() does not exist on Task. It seems like you code against a sub-type of Task such as PhingCallTask or ForeachTask or PhingTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

146
        $this->callee->/** @scrutinizer ignore-call */ 
147
                       addReference($r);
Loading history...
147 1
    }
148
149
    /**
150
     *  init this task by creating new instance of the phing task and
151
     *  configuring it's by calling its own init method.
152
     */
153 9
    public function init()
154
    {
155 9
        $this->callee = $this->project->createTask("phing");
156 9
        $this->callee->setOwningTarget($this->getOwningTarget());
157 9
        $this->callee->setTaskName($this->getTaskName());
158 9
        $this->callee->setHaltOnFailure(true);
0 ignored issues
show
Bug introduced by
The method setHaltOnFailure() does not exist on Task. It seems like you code against a sub-type of Task such as XmlLintTask or PatchTask or PhingTask or PHPUnitTask or JslLintTask or PhpLintTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

158
        $this->callee->/** @scrutinizer ignore-call */ 
159
                       setHaltOnFailure(true);
Loading history...
159 9
        $this->callee->setLocation($this->getLocation());
160 9
        $this->callee->init();
161 9
    }
162
163
    /**
164
     *  hand off the work to the phing task of ours, after setting it up
165
     *
166
     * @throws BuildException on validation failure or if the target didn't
167
     *                        execute
168
     */
169 8
    public function main()
170
    {
171 8
        if ($this->getOwningTarget()->getName() === "") {
172
            $this->log("Cowardly refusing to call target '{$this->subTarget}' from the root", Project::MSG_WARN);
173
            return;
174
        }
175
176 8
        $this->log("Running PhingCallTask for target '" . $this->subTarget . "'", Project::MSG_DEBUG);
177 8
        if ($this->callee === null) {
178
            $this->init();
179
        }
180
181 8
        if ($this->subTarget === null) {
182
            throw new BuildException("Attribute target is required.", $this->getLocation());
183
        }
184
185 8
        $this->callee->setPhingFile($this->project->getProperty("phing.file"));
0 ignored issues
show
Bug introduced by
The method setPhingFile() does not exist on Task. It seems like you code against a sub-type of Task such as PhingTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

185
        $this->callee->/** @scrutinizer ignore-call */ 
186
                       setPhingFile($this->project->getProperty("phing.file"));
Loading history...
186 8
        $this->callee->setTarget($this->subTarget);
187 8
        $this->callee->setInheritAll($this->inheritAll);
0 ignored issues
show
Bug introduced by
The method setInheritAll() does not exist on Task. It seems like you code against a sub-type of Task such as PhingCallTask or ForeachTask or PhingTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

187
        $this->callee->/** @scrutinizer ignore-call */ 
188
                       setInheritAll($this->inheritAll);
Loading history...
188 8
        $this->callee->setInheritRefs($this->inheritRefs);
0 ignored issues
show
Bug introduced by
The method setInheritRefs() does not exist on Task. It seems like you code against a sub-type of Task such as PhingCallTask or ForeachTask or PhingTask. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

188
        $this->callee->/** @scrutinizer ignore-call */ 
189
                       setInheritRefs($this->inheritRefs);
Loading history...
189 8
        $this->callee->main();
190 8
    }
191
}
192