Passed
Push — master ( 6d2fbf...b5fd66 )
by Théo
02:44 queued 48s
created

Container::getPrinter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the humbug/php-scoper package.
7
 *
8
 * Copyright (c) 2017 Théo FIDRY <[email protected]>,
9
 *                    Pádraic Brady <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace Humbug\PhpScoper;
16
17
use Humbug\PhpScoper\Configuration\ConfigurationFactory;
18
use Humbug\PhpScoper\Configuration\RegexChecker;
19
use Humbug\PhpScoper\Configuration\SymbolsConfigurationFactory;
20
use Humbug\PhpScoper\PhpParser\Printer\Printer;
21
use Humbug\PhpScoper\PhpParser\Printer\StandardPrinter;
22
use Humbug\PhpScoper\Scoper\ScoperFactory;
23
use Humbug\PhpScoper\Symbol\EnrichedReflectorFactory;
24
use Humbug\PhpScoper\Symbol\Reflector;
25
use PhpParser\Lexer;
26
use PhpParser\Parser;
27
use PhpParser\ParserFactory;
28
use PhpParser\PrettyPrinter\Standard;
29
use Symfony\Component\Filesystem\Filesystem;
30
31
final class Container
32
{
33
    private Filesystem $filesystem;
34
    private ConfigurationFactory $configFactory;
35
    private Parser $parser;
36
    private Reflector $reflector;
37
    private ScoperFactory $scoperFactory;
38
    private EnrichedReflectorFactory $enrichedReflectorFactory;
39
    private Printer $printer;
40
41
    public function getFileSystem(): Filesystem
42
    {
43
        if (!isset($this->filesystem)) {
44
            $this->filesystem = new Filesystem();
45
        }
46
47
        return $this->filesystem;
48
    }
49
50
    public function getConfigurationFactory(): ConfigurationFactory
51
    {
52
        if (!isset($this->configFactory)) {
53
            $this->configFactory = new ConfigurationFactory(
54
                $this->getFileSystem(),
55
                new SymbolsConfigurationFactory(
56
                    new RegexChecker(),
57
                ),
58
            );
59
        }
60
61
        return $this->configFactory;
62
    }
63
64
    public function getScoperFactory(): ScoperFactory
65
    {
66
        if (!isset($this->scoperFactory)) {
67
            $this->scoperFactory = new ScoperFactory(
68
                $this->getParser(),
69
                $this->getEnrichedReflectorFactory(),
70
                $this->getPrinter(),
71
            );
72
        }
73
74
        return $this->scoperFactory;
75
    }
76
77
    public function getParser(): Parser
78
    {
79
        if (!isset($this->parser)) {
80
            $this->parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new Lexer());
81
        }
82
83
        return $this->parser;
84
    }
85
86
    public function getReflector(): Reflector
87
    {
88
        if (!isset($this->reflector)) {
89
            $this->reflector = Reflector::createWithPhpStormStubs();
90
        }
91
92
        return $this->reflector;
93
    }
94
95
    public function getEnrichedReflectorFactory(): EnrichedReflectorFactory
96
    {
97
        if (!isset($this->enrichedReflectorFactory)) {
98
            $this->enrichedReflectorFactory = new EnrichedReflectorFactory(
99
                $this->getReflector(),
100
            );
101
        }
102
103
        return $this->enrichedReflectorFactory;
104
    }
105
106
    public function getPrinter(): Printer
107
    {
108
        if (!isset($this->printer)) {
109
            $this->printer = new StandardPrinter(
110
                new Standard(),
111
            );
112
        }
113
114
        return $this->printer;
115
    }
116
}
117