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

PropertyCopy::setFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 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