Completed
Pull Request — master (#19)
by Auke
01:42
created

Writer::preamble()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 19
ccs 0
cts 0
cp 0
rs 8.8571
cc 6
eloc 14
nc 10
nop 3
crap 42
1
<?php
2
/*
3
 * This file is part of the Ariadne Component Library.
4
 *
5
 * (c) Muze <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace arc\xml;
12
13
/**
14
 * This class allows you to create valid and nicely indented XML strings
15
 * Any method called on it is interpreted as a new XML element to create.
16
 */
17
class Writer {
18
19
    /**
20
     * @var string $indent The string to ident each level with. Default is a tab.
21
     */
22
    public $indent = "\t";
23
24
    /**
25
     * @var string $newLine The string to use as a new line or linebreak. Defaults to \r\n.
26
     */
27
    public $newLine = "\r\n";
28
29
    /**
30
     * @param array $options allows you to set the indent and newLine
31
     * options immediately upon construction
32
     */
33 1
    public function __construct( $options = [])
34
    {
35 1
        $optionList = [ 'indent', 'newLine' ];
36 1
        foreach( $options as $option => $optionValue) {
37
            if (in_array( $option, $optionList )) {
38
                $this->{$option} = $optionValue;
39
            }
40 1
        }
41 1
    }
42
43 2
    public function __call( $name, $args)
44
    {	
45 2
        return call_user_func_array( [ new NodeList( [], $this ), $name ], $args );
46
    }
47
48
}
49