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

EchoXML   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 72.72%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 50
rs 10
ccs 16
cts 22
cp 0.7272
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A main() 0 24 5
A setAppend() 0 3 1
A setFile() 0 3 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
 * Echos a message to the logging system or to a file
22
 *
23
 * @author Siad Ardroumli <[email protected]>
24
 * @package phing.tasks.system
25
 */
26
class EchoXML extends XMLFragment
27
{
28
    private $file;
29
30
    private $append = false;
31
32
    /**
33
     * setter for file
34
     *
35
     * @param string $file
36
     */
37 1
    public function setFile(string $file): void
38
    {
39 1
        $this->file = $file;
40 1
    }
41
42
    /**
43
     * setter for append
44
     *
45
     * @param bool $append
46
     */
47
    public function setAppend(bool $append): void
48
    {
49
        $this->append = $append;
50
    }
51
52 2
    public function main()
53
    {
54 2
        $n = $this->getFragment()->firstChild;
55 2
        if ($n === null) {
56 1
            throw new BuildException('No nested XML specified');
57
        }
58 1
        $doc = $this->getDoc();
59 1
        $doc->formatOutput = true;
60 1
        $xml = $doc->saveXML($n);
61 1
        if ($xml === false) {
62
            throw new BuildException('Error in xml detected');
63
        }
64 1
        if (empty($this->file)) {
65
            $this->log($xml);
66
        } else {
67 1
            if ($this->append) {
68
                $handle = fopen($this->file, 'ab');
69
            } else {
70 1
                $handle = fopen($this->file, 'wb');
71
            }
72
73 1
            fwrite($handle, $xml);
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $handle of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

73
            fwrite(/** @scrutinizer ignore-type */ $handle, $xml);
Loading history...
74
75 1
            fclose($handle);
0 ignored issues
show
Bug introduced by
It seems like $handle can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

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

75
            fclose(/** @scrutinizer ignore-type */ $handle);
Loading history...
76
        }
77 1
    }
78
}
79