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

PropertyCopy   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 78.26%

Importance

Changes 0
Metric Value
wmc 9
eloc 17
dl 0
loc 58
rs 10
c 0
b 0
f 0
ccs 18
cts 23
cp 0.7826

5 Methods

Rating   Name   Duplication   Size   Complexity  
A main() 0 12 4
A validate() 0 5 2
A setSilent() 0 3 1
A setFrom() 0 3 1
A __construct() 0 5 1
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
namespace Phing\Task\System\Property;
21
22
use Phing\Exception\BuildException;
23
use Phing\Task\System\Property\AbstractPropertySetterTask;
24
25
/**
26
 * PropertyCopy
27
 *
28
 * @author  Siad Ardroumli <[email protected]>
29
 * @package phing.tasks.ext.property
30
 */
31
class PropertyCopy extends AbstractPropertySetterTask
32
{
33
    /**
34
     * @var string $from
35
     */
36
    private $from;
37
38
    /**
39
     * @var bool $silent
40
     */
41
    private $silent;
42
43
    /***
44
     * Default Constructor
45
     */
46 1
    public function __construct()
47
    {
48 1
        parent::__construct();
49 1
        $this->from = null;
50 1
        $this->silent = false;
51 1
    }
52
53
    /**
54
     * @param string $from
55
     */
56 1
    public function setFrom($from)
57
    {
58 1
        $this->from = $from;
59 1
    }
60
61
    /**
62
     * @param bool $silent
63
     */
64
    public function setSilent($silent)
65
    {
66
        $this->silent = $silent;
67
    }
68
69 1
    protected function validate()
70
    {
71 1
        parent::validate();
72 1
        if ($this->from === null) {
73
            throw new BuildException("Missing the 'from' attribute.");
74
        }
75 1
    }
76
77 1
    public function main()
78
    {
79 1
        $this->validate();
80
81 1
        $value = $this->getProject()->getProperty($this->from);
82
83 1
        if ($value === null && !$this->silent) {
0 ignored issues
show
introduced by
The condition $value === null is always false.
Loading history...
84
            throw new BuildException("Property '{$this->from}' is not defined.");
85
        }
86
87 1
        if ($value !== null) {
0 ignored issues
show
introduced by
The condition $value !== null is always true.
Loading history...
88 1
            $this->setPropertyValue($value);
89
        }
90 1
    }
91
}
92