Completed
Push — feature/merge-build-stop-step ( d59daf )
by Tom
8s
created

FileWriter::createByFilepath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 2
eloc 9
nc 2
nop 1
1
<?php
2
3
namespace N98\Magento\Command\Developer\Console\Util\Config;
4
5
class FileWriter extends \DOMDocument
6
{
7
    /**
8
     * @var string
9
     */
10
    protected static $defaultXml = '<config></config>';
11
12
    /**
13
     * @param string $filepath
14
     * @return FileWriter
15
     */
16
    public static function createByFilepath($filepath)
17
    {
18
        $dom = new static('1.0', 'UTF-8');
19
        $dom->formatOutput = true;
20
        $dom->preserveWhiteSpace = false;
21
22
        if (file_exists($filepath)) {
23
            $dom->load($filepath);
24
        } else {
25
            $dom->loadXML(static::$defaultXml);
26
        }
27
28
        return $dom;
29
    }
30
}
31