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

URLEncodeTask::setRefid()   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\Project;
24
use Phing\Task\System\Property\AbstractPropertySetterTask;
25
use Phing\Type\Reference;
26
27
/**
28
 * @author    Siad Ardroumli <[email protected]>
29
 * @package   phing.tasks.ext.property
30
 */
31
class URLEncodeTask extends AbstractPropertySetterTask
32
{
33
    /**
34
     * @var string
35
     */
36
    private $value = '';
37
38
    /**
39
     * @var Reference
40
     */
41
    private $ref;
42
43 2
    public function setValue(string $value)
44
    {
45 2
        $this->value = urlencode($value);
46 2
    }
47
48 2
    public function getValue(Project $p): string
49
    {
50 2
        if ($this->ref !== null) {
51 1
            $this->setValue($this->ref->getReferencedObject($p));
0 ignored issues
show
Bug introduced by
$this->ref->getReferencedObject($p) of type object is incompatible with the type string expected by parameter $value of Phing\Task\System\Proper...LEncodeTask::setValue(). ( Ignorable by Annotation )

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

51
            $this->setValue(/** @scrutinizer ignore-type */ $this->ref->getReferencedObject($p));
Loading history...
52
        }
53
54 2
        return $this->value;
55
    }
56
57 1
    public function setRefid(Reference $ref)
58
    {
59 1
        $this->ref = $ref;
60 1
    }
61
62
    public function __toString()
63
    {
64
        return $this->value;
65
    }
66
67
    protected function validate()
68
    {
69
        parent::validate();
70
        if ($this->value === null && $this->ref === null) {
71
            throw new BuildException(
72
                'You must specify value or refid with the name attribute',
73
                $this->getLocation()
74
            );
75
        }
76
    }
77
78 2
    public function main()
79
    {
80 2
        parent::validate();
81 2
        $val = $this->getValue($this->getProject());
82 2
        $this->setPropertyValue($val);
83 2
    }
84
}
85