Container::getFileSystem()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
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
    private Lexer $lexer;
41
42
    public function getFileSystem(): Filesystem
43
    {
44
        if (!isset($this->filesystem)) {
45
            $this->filesystem = new Filesystem();
46
        }
47
48
        return $this->filesystem;
49
    }
50
51
    public function getConfigurationFactory(): ConfigurationFactory
52
    {
53
        if (!isset($this->configFactory)) {
54
            $this->configFactory = new ConfigurationFactory(
55
                $this->getFileSystem(),
56
                new SymbolsConfigurationFactory(
57
                    new RegexChecker(),
58
                ),
59
            );
60
        }
61
62
        return $this->configFactory;
63
    }
64
65
    public function getScoperFactory(): ScoperFactory
66
    {
67
        if (!isset($this->scoperFactory)) {
68
            $this->scoperFactory = new ScoperFactory(
69
                $this->getParser(),
70
                $this->getEnrichedReflectorFactory(),
71
                $this->getPrinter(),
72
                $this->getLexer(),
73
            );
74
        }
75
76
        return $this->scoperFactory;
77
    }
78
79
    public function getParser(): Parser
80
    {
81
        if (!isset($this->parser)) {
82
            $this->parser = (new ParserFactory())->create(
83
                ParserFactory::PREFER_PHP7,
84
                $this->getLexer(),
85
            );
86
        }
87
88
        return $this->parser;
89
    }
90
91
    public function getReflector(): Reflector
92
    {
93
        if (!isset($this->reflector)) {
94
            $this->reflector = Reflector::createWithPhpStormStubs();
95
        }
96
97
        return $this->reflector;
98
    }
99
100
    public function getEnrichedReflectorFactory(): EnrichedReflectorFactory
101
    {
102
        if (!isset($this->enrichedReflectorFactory)) {
103
            $this->enrichedReflectorFactory = new EnrichedReflectorFactory(
104
                $this->getReflector(),
105
            );
106
        }
107
108
        return $this->enrichedReflectorFactory;
109
    }
110
111
    public function getPrinter(): Printer
112
    {
113
        if (!isset($this->printer)) {
114
            $this->printer = new StandardPrinter(
115
                new Standard(),
116
            );
117
        }
118
119
        return $this->printer;
120
    }
121
122
    public function getLexer(): Lexer
123
    {
124
        if (!isset($this->lexer)) {
125
            $this->lexer = new Lexer();
126
        }
127
128
        return $this->lexer;
129
    }
130
}
131