Passed
Push — main ( 28d658...6dddcc )
by Michiel
06:12
created

AbstractPropertySetterTask   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 0
Metric Value
wmc 8
eloc 18
c 0
b 0
f 0
dl 0
loc 39
ccs 15
cts 17
cp 0.8824
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 4 2
A setProperty() 0 3 1
A setOverride() 0 3 1
A setPropertyValue() 0 17 4
1
<?php
2
3
namespace Phing\Task\System\Property;
4
5
use Phing\Exception\BuildException;
6
use Phing\Task;
7
use Phing\Task\System\PropertyTask;
8
9
/**
10
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
16
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
17
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
18
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
20
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
 *
22
 * This software consists of voluntary contributions made by many individuals
23
 * and is licensed under the LGPL. For more information please see
24
 * <http://phing.info>.
25
 */
26
abstract class AbstractPropertySetterTask extends Task
27
{
28
    private $property;
29
    private $override = false;
30
31 1
    public function setOverride($override)
32
    {
33 1
        $this->override = $override;
34
    }
35
36 11
    public function setProperty($property)
37
    {
38 11
        $this->property = $property;
39
    }
40
41 8
    protected function validate()
42
    {
43 8
        if (null == $this->property) {
44
            throw new BuildException('You must specify a property to set.');
45
        }
46
    }
47
48 11
    protected function setPropertyValue($value)
49
    {
50 11
        if (null !== $value) {
51 11
            if ($this->override) {
52 1
                if (null == $this->getProject()->getUserProperty($this->property)) {
53 1
                    $this->getProject()->setProperty($this->property, $value);
54
                } else {
55
                    $this->getProject()->setUserProperty($this->property, $value);
56
                }
57
            } else {
58
                /**
59
                 * @var PropertyTask
60
                 */
61 10
                $p = $this->project->createTask('property');
62 10
                $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\Ext\PhkPackage\PhkPackageTask or Phing\Task\System\RecorderTask or Phing\Task\Ext\GrowlNotifyTask or Phing\Task\System\TaskdefTask or Phing\Task\System\PropertyTask or Phing\Task\System\TypedefTask or Phing\Task\System\AdhocTypedefTask or Phing\Task\System\AdhocTaskdefTask or Phing\Task\Ext\Hg\HgTagTask or Phing\Task\Ext\StopwatchTask or Phing\Task\Ext\Git\GitTagTask. ( Ignorable by Annotation )

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

62
                $p->/** @scrutinizer ignore-call */ 
63
                    setName($this->property);
Loading history...
63 10
                $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

63
                $p->/** @scrutinizer ignore-call */ 
64
                    setValue($value);
Loading history...
64 10
                $p->main();
65
            }
66
        }
67
    }
68
}
69