Completed
Push — master ( 5bac00...4dd860 )
by Nikola
02:03
created

Printer::dump()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * This file is part of the Abstract builder package, an RunOpenCode project.
4
 *
5
 * (c) 2017 RunOpenCode
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace RunOpenCode\AbstractBuilder\Ast;
11
12
use PhpParser\PrettyPrinter\Standard;
13
use RunOpenCode\AbstractBuilder\Ast\Metadata\FileMetadata;
14
15
/**
16
 * Class Printer
17
 *
18
 * @package RunOpenCode\AbstractBuilder\Ast
19
 */
20
class Printer extends Standard
21
{
22
    /**
23
     * @var Printer
24
     */
25
    private static $instance;
26
27
    /**
28
     * Get shared printer instance. Singleton implementation.
29
     *
30
     * @return Printer|static
31
     */
32 2
    public static function getInstance()
33
    {
34 2
        if (null === self::$instance) {
35
36 1
            self::$instance = new static([
37 1
                'shortArraySyntax' => true
38
            ]);
39
        }
40
41 2
        return self::$instance;
42
    }
43
44
    /**
45
     * Get PHP code for file metadata.
46
     *
47
     * @param FileMetadata $file
48
     *
49
     * @return string
50
     */
51 2
    public function print(FileMetadata $file)
52
    {
53 2
        return $this->prettyPrintFile($file->getAst());
54
    }
55
56
    /**
57
     * Save PHP code for file metadata into file.
58
     *
59
     * @param FileMetadata $file
60
     */
61 1
    public function dump(FileMetadata $file)
62
    {
63 1
        file_put_contents($file->getFilename(), $this->print($file));
64 1
    }
65
}
66