Passed
Pull Request — master (#491)
by Théo
02:26
created

Container::getReflector()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 7
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 Scoper $scoper;
35
36
    public function getFileSystem(): Filesystem
37
    {
38
        if (!isset($this->filesystem)) {
39
            $this->filesystem = new Filesystem();
40
        }
41
42
        return $this->filesystem;
43
    }
44
45
    public function getConfigurationFactory(): ConfigurationFactory
46
    {
47
        if (!isset($this->configFactory)) {
48
            $this->configFactory = new ConfigurationFactory(
49
                $this->getFileSystem(),
50
            );
51
        }
52
53
        return $this->configFactory;
54
    }
55
56
    public function getScoper(): Scoper
57
    {
58
        if (!isset($this->scoper)) {
59
            $this->scoper = new PatchScoper(
60
                new PhpScoper(
61
                    $this->getParser(),
62
                    new JsonFileScoper(
63
                        new InstalledPackagesScoper(
64
                            new SymfonyScoper(
65
                                new NullScoper()
66
                            )
67
                        )
68
                    ),
69
                    new TraverserFactory(new Reflector())
70
                )
71
            );
72
        }
73
74
        return $this->scoper;
75
    }
76
77
    public function getParser(): Parser
78
    {
79
        if (!isset($this->parser)) {
80
            $this->parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer());
81
        }
82
83
        return $this->parser;
84
    }
85
}
86