Printer::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
6
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
8
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
10
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
11
 * THE SOFTWARE.
12
 *
13
 * This software consists of voluntary contributions made by many individuals
14
 * and is licensed under the MIT license.
15
 *
16
 * Copyright (c) 2018 Yuuki Takezawa
17
 */
18
19
namespace Ytake\Lom;
20
21
use PhpParser\PrettyPrinterAbstract;
22
23
/**
24
 * Class Printer.
25
 *
26
 * @author yuuki.takezawa<[email protected]>
27
 */
28
class Printer
29
{
30
    /** @var array */
31
    protected $parsed;
32
33
    /** @var PrettyPrinterAbstract */
34
    protected $printer;
35
36
    /**
37
     * @param PrettyPrinterAbstract $printer
38
     */
39
    public function __construct(PrettyPrinterAbstract $printer)
40
    {
41
        $this->printer = $printer;
42
    }
43
44
    /**
45
     * @param array $parsed
46
     *
47
     * @return Printer
48
     */
49
    public function setStatement(array $parsed): Printer
50
    {
51
        $this->parsed = $parsed;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @return null|string
58
     */
59
    public function display(): ?string
60
    {
61
        return $this->printer->prettyPrint($this->parsed);
62
    }
63
64
    /**
65
     * @param string $fileName
66
     */
67
    public function putFile(string $fileName): void
68
    {
69
        file_put_contents($fileName, $this->printer->prettyPrintFile($this->parsed));
70
    }
71
}
72