Completed
Push — master ( 9e0037...b2adab )
by Siad
12:57
created

XMLChild   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 68.42%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 62
rs 10
ccs 13
cts 19
cp 0.6842
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addText() 0 7 3
A __construct() 0 6 1
A setDynamicAttribute() 0 3 1
A customChildCreator() 0 6 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
/**
21
 * @author Siad Ardroumli <[email protected]>
22
 * @package phing.system.util
23
 */
24
class XMLChild implements DynamicConfigurator
25
{
26
    /**
27
     * @var DOMElement
28
     */
29
    private $e;
30
    /**
31
     * @var DOMDocument
32
     */
33
    private $d;
34
    /**
35
     * @var DOMDocumentFragment
36
     */
37
    private $f;
38
    /**
39
     * @var Project
40
     */
41
    private $p;
42
43
    /**
44
     * XMLChild constructor.
45
     * @param Project $p
46
     * @param DOMDocument $d
47
     * @param DOMDocumentFragment $f
48
     * @param DOMElement $e
49
     */
50 1
    public function __construct(Project $p, \DOMDocument $d, \DOMDocumentFragment $f, \DOMElement $e)
51
    {
52 1
        $this->p = $p;
53 1
        $this->d = $d;
54 1
        $this->f = $f;
55 1
        $this->e = $e;
56 1
    }
57
58
    /**
59
     * Add nested text.
60
     * @param string $s the text to add
61
     */
62
    public function addText(string $s): void
63
    {
64
        $s = $this->p->replaceProperties($s);
65
        //only text nodes that are non null after property expansion are added
66
        if ($s !== null && trim($s) !== '') {
67
            $t = $this->d->createTextNode(trim($s));
68
            $this->e->appendChild($t);
69
        }
70
    }
71
72 1
    public function setDynamicAttribute(string $name, string $value): void
73
    {
74 1
        $this->e->setAttribute($name, $value);
75 1
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80 1
    public function customChildCreator($elementName, Project $project)
81
    {
82 1
        $e2 = $this->d->createElement($elementName);
83
84 1
        $this->e->appendChild($e2);
85 1
        return new self($this->p, $this->d, $this->f, $e2);
86
    }
87
}
88