Completed
Push — master ( bc194a...d90c8b )
by Siad
17:01
created

AbstractPropertySetterTask::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 0
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 2.1481
rs 10
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
abstract class AbstractPropertySetterTask extends Task
22
{
23
    private $property;
24
    private $override = false;
25
26 1
    public function setOverride($override)
27
    {
28 1
        $this->override = $override;
29 1
    }
30
31 10
    public function setProperty($property)
32
    {
33 10
        $this->property = $property;
34 10
    }
35
36 7
    protected function validate()
37
    {
38 7
        if ($this->property == null) {
39
            throw new BuildException("You must specify a property to set.");
40
        }
41 7
    }
42
43 10
    protected function setPropertyValue($value)
44
    {
45 10
        if ($value !== null) {
46 10
            if ($this->override) {
47 1
                if ($this->getProject()->getUserProperty($this->property) == null) {
48 1
                    $this->getProject()->setProperty($this->property, $value);
49
                } else {
50
                    $this->getProject()->setUserProperty($this->property, $value);
51
                }
52
            } else {
53 9
                $p = $this->project->createTask("property");
54 9
                $p->setName($this->property);
0 ignored issues
show
Bug introduced by
The method setName() does not exist on Task. It seems like you code against a sub-type of Task such as TaskdefTask or PhkPackageTask or RecorderTask or GrowlNotifyTask or PackageAsPathTask or TypedefTask or PropertyTask or PathToFileSet or AdhocTypedefTask or AdhocTaskdefTask or GitTagTask or HgTagTask or PearPackageTask or StopwatchTask. ( Ignorable by Annotation )

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

54
                $p->/** @scrutinizer ignore-call */ 
55
                    setName($this->property);
Loading history...
55 9
                $p->setValue($value);
0 ignored issues
show
Bug introduced by
The method setValue() does not exist on Task. It seems like you code against a sub-type of Task such as UpToDateTask or AvailableTask or SwitchTask or PropertyTask or CaseTask or URLEncodeTask or SortList. ( Ignorable by Annotation )

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

55
                $p->/** @scrutinizer ignore-call */ 
56
                    setValue($value);
Loading history...
56 9
                $p->main();
57
            }
58
        }
59 10
    }
60
}
61