Passed
Pull Request — master (#488)
by Théo
02:04
created

Container::getConfigurationFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
rs 10
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\PhpParser\TraverserFactory;
18
use Humbug\PhpScoper\Scoper\Composer\InstalledPackagesScoper;
19
use Humbug\PhpScoper\Scoper\Composer\JsonFileScoper;
20
use Humbug\PhpScoper\Scoper\NullScoper;
21
use Humbug\PhpScoper\Scoper\PatchScoper;
22
use Humbug\PhpScoper\Scoper\PhpScoper;
23
use Humbug\PhpScoper\Scoper\SymfonyScoper;
24
use PhpParser\Lexer;
25
use PhpParser\Parser;
26
use PhpParser\ParserFactory;
27
use Symfony\Component\Filesystem\Filesystem;
28
29
final class Container
30
{
31
    private Filesystem $filesystem;
32
    private ConfigurationFactory $configFactory;
33
    private Parser $parser;
34
    private Reflector $reflector;
35
    private Scoper $scoper;
36
37
    public function getFileSystem(): Filesystem
38
    {
39
        if (!isset($this->filesystem)) {
40
            $this->filesystem = new Filesystem();
41
        }
42
43
        return $this->filesystem;
44
    }
45
46
    public function getConfigurationFactory(): ConfigurationFactory
47
    {
48
        if (!isset($this->configFactory)) {
49
            $this->configFactory = new ConfigurationFactory(
50
                $this->getFileSystem(),
51
            );
52
        }
53
54
        return $this->configFactory;
55
    }
56
57
    public function getScoper(): Scoper
58
    {
59
        if (!isset($this->scoper)) {
60
            $this->scoper = new PatchScoper(
61
                new PhpScoper(
62
                    $this->getParser(),
63
                    new JsonFileScoper(
64
                        new InstalledPackagesScoper(
65
                            new SymfonyScoper(
66
                                new NullScoper()
67
                            )
68
                        )
69
                    ),
70
                    new TraverserFactory($this->getReflector())
71
                )
72
            );
73
        }
74
75
        return $this->scoper;
76
    }
77
78
    public function getParser(): Parser
79
    {
80
        if (!isset($this->parser)) {
81
            $this->parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer());
82
        }
83
84
        return $this->parser;
85
    }
86
87
    public function getReflector(): Reflector
88
    {
89
        if (!isset($this->reflector)) {
90
            $this->reflector = new Reflector();
91
        }
92
93
        return $this->reflector;
94
    }
95
}
96