Passed
Push — master ( 534b00...f15154 )
by Théo
02:15
created

CompatibilityScoper::scope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Humbug\PhpScoper\Scoper;
6
7
use Humbug\PhpScoper\Symbol\SymbolsRegistry;
8
use Humbug\PhpScoper\Whitelist;
9
use function func_get_args;
10
11
/**
12
 * Ensures the symbols registered to the symbols registry (the new API) are
13
 * added back to the Whitelist (the old API).
14
 * This Compatibility layer should only be required until the Box API is adapted.
15
 */
16
final class CompatibilityScoper implements Scoper
17
{
18
    private Scoper $decoratedScoper;
19
    private Whitelist $whitelist;
20
    private SymbolsRegistry $symbolsRegistry;
21
22
    public function __construct(
23
        Scoper $decoratedScoper,
24
        Whitelist $whitelist,
25
        SymbolsRegistry $symbolsRegistry
26
    ) {
27
        $this->decoratedScoper = $decoratedScoper;
28
        $this->whitelist = $whitelist;
29
        $this->symbolsRegistry = $symbolsRegistry;
30
    }
31
32
    public function scope(string $filePath, string $contents): string
33
    {
34
        $scopedContents = $this->decoratedScoper->scope(...func_get_args());
35
36
        $this->whitelist->registerFromRegistry($this->symbolsRegistry);
37
38
        return $scopedContents;
39
    }
40
}
41