Passed
Push — master ( 7a9799...2aee06 )
by Michiel
06:03
created

AbstractPropertySetterTask::setPropertyValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
rs 9.9
c 0
b 0
f 0
ccs 10
cts 10
cp 1
cc 4
nc 4
nop 1
crap 4
1
<?php
2
3
namespace Phing\Task\System\Property;
4
5
use Phing\Exception\BuildException;
6
use Phing\Task;
7
8
/**
9
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
13
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
14
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
15
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
16
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
17
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
19
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
20
 *
21
 * This software consists of voluntary contributions made by many individuals
22
 * and is licensed under the LGPL. For more information please see
23
 * <http://phing.info>.
24
 */
25
abstract class AbstractPropertySetterTask extends Task
26
{
27
    private $property;
28
    private $override = false;
29
30 1
    public function setOverride($override)
31
    {
32 1
        $this->override = $override;
33 1
    }
34
35 10
    public function setProperty($property)
36
    {
37 10
        $this->property = $property;
38 10
    }
39
40 7
    protected function validate()
41
    {
42 7
        if ($this->property == null) {
43
            throw new BuildException("You must specify a property to set.");
44
        }
45 7
    }
46
47 10
    protected function setPropertyValue($value)
48
    {
49 10
        if ($value !== null) {
50 10
            if ($this->override) {
51 1
                if ($this->getProject()->getUserProperty($this->property) == null) {
52 1
                    $this->getProject()->setProperty($this->property, $value);
53
                } else {
54 1
                    $this->getProject()->setUserProperty($this->property, $value);
55
                }
56
            } else {
57 9
                $p = $this->project->createTask("property");
58 9
                $p->setName($this->property);
0 ignored issues
show
Bug introduced by
The method setName() does not exist on Phing\Task. It seems like you code against a sub-type of Phing\Task such as Phing\Task\System\Property\PathToFileSet or Phing\Task\System\RecorderTask or Phing\Task\System\TaskdefTask or Phing\Task\Ext\PhkPackageTask or GrowlNotifyTask or Phing\Task\System\PropertyTask or PackageAsPathTask or Phing\Task\System\TypedefTask or Phing\Task\System\AdhocTypedefTask or Phing\Task\System\AdhocTaskdefTask or Phing\Task\Ext\GitTagTask or StopwatchTask or Phing\Task\Ext\HgTagTask. ( Ignorable by Annotation )

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

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

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

59
                $p->/** @scrutinizer ignore-call */ 
60
                    setValue($value);
Loading history...
60 9
                $p->main();
61
            }
62
        }
63 10
    }
64
}
65