Passed
Push — master ( e0a8ac...1d0e74 )
by Théo
02:19
created

ScoperFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createScoper() 0 33 1
A __construct() 0 3 1
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\Scoper;
16
17
use Humbug\PhpScoper\Configuration\Configuration;
18
use Humbug\PhpScoper\PhpParser\TraverserFactory;
19
use Humbug\PhpScoper\Reflector;
20
use Humbug\PhpScoper\Scoper\Composer\AutoloadPrefixer;
21
use Humbug\PhpScoper\Scoper\Composer\InstalledPackagesScoper;
22
use Humbug\PhpScoper\Scoper\Composer\JsonFileScoper;
23
use PhpParser\Parser;
24
25
/**
26
 * @final
27
 */
28
class ScoperFactory
29
{
30
    private Parser $parser;
31
32
    public function __construct(Parser $parser)
33
    {
34
        $this->parser = $parser;
35
    }
36
37
    public function createScoper(Configuration $configuration): Scoper
38
    {
39
        $prefix = $configuration->getPrefix();
40
        $whitelist = $configuration->getWhitelist();
41
42
        $autoloadPrefix = new AutoloadPrefixer($prefix, $whitelist);
43
44
        return new PatchScoper(
45
            new PhpScoper(
46
                $this->parser,
47
                new JsonFileScoper(
48
                    new InstalledPackagesScoper(
49
                        new SymfonyScoper(
50
                            new NullScoper(),
51
                            $prefix,
52
                            $whitelist,
53
                        ),
54
                        $autoloadPrefix
55
                    ),
56
                    $autoloadPrefix
57
                ),
58
                new TraverserFactory(
59
                    Reflector::createWithPhpStormStubs()->withSymbols(
60
                        $configuration->getInternalClasses(),
61
                        $configuration->getInternalFunctions(),
62
                        $configuration->getInternalConstants(),
63
                    ),
64
                ),
65
                $prefix,
66
                $whitelist,
67
            ),
68
            $prefix,
69
            $configuration->getPatcher(),
70
        );
71
    }
72
}
73