Passed
Pull Request — master (#492)
by Théo
01:52
created

Container::getScoperFactory()   A

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
c 0
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 PhpParser\Lexer;
18
use PhpParser\Parser;
19
use PhpParser\ParserFactory;
20
use Symfony\Component\Filesystem\Filesystem;
21
22
final class Container
23
{
24
    private Filesystem $filesystem;
25
    private ConfigurationFactory $configFactory;
26
    private Parser $parser;
27
    private ScoperFactory $scoperFactory;
28
29
    public function getFileSystem(): Filesystem
30
    {
31
        if (!isset($this->filesystem)) {
32
            $this->filesystem = new Filesystem();
33
        }
34
35
        return $this->filesystem;
36
    }
37
38
    public function getConfigurationFactory(): ConfigurationFactory
39
    {
40
        if (!isset($this->configFactory)) {
41
            $this->configFactory = new ConfigurationFactory(
42
                $this->getFileSystem(),
43
            );
44
        }
45
46
        return $this->configFactory;
47
    }
48
49
    public function getScoperFactory(): ScoperFactory
50
    {
51
        if (!isset($this->scoperFactory)) {
52
            $this->scoperFactory = new ScoperFactory($this->getParser());
53
        }
54
55
        return $this->scoperFactory;
56
    }
57
58
    public function getParser(): Parser
59
    {
60
        if (!isset($this->parser)) {
61
            $this->parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7, new Lexer());
62
        }
63
64
        return $this->parser;
65
    }
66
}
67