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

Container   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 43
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigurationFactory() 0 9 2
A getFileSystem() 0 7 2
A getScoperFactory() 0 7 2
A getParser() 0 7 2
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