Passed
Push — master ( 79dbb9...e698c4 )
by Théo
02:08
created

EnrichedReflector   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 49
rs 10
c 1
b 0
f 0
wmc 11

7 Methods

Rating   Name   Duplication   Size   Complexity  
A belongsToExcludedNamespace() 0 3 1
A isFunctionInternal() 0 3 1
A isExposedClass() 0 6 3
A isConstantInternal() 0 3 1
A isClassInternal() 0 3 1
A __construct() 0 4 1
A isExposedConstant() 0 9 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Humbug\PhpScoper\Symbol;
6
7
use Humbug\PhpScoper\Reflector;
8
use Humbug\PhpScoper\Whitelist;
9
10
/**
11
 * Combines the API or the "traditional" reflector which is about to tell
12
 * if a symbol is internal or not with the more PHP-Scoper specific exposed
13
 * API.
14
 */
15
final class EnrichedReflector
16
{
17
    private Reflector $reflector;
18
    private Whitelist $whitelist;
19
20
    public function __construct(Reflector $reflector, Whitelist $whitelist)
21
    {
22
        $this->reflector = $reflector;
23
        $this->whitelist = $whitelist;
24
    }
25
26
    public function belongsToExcludedNamespace(string $name): bool
27
    {
28
        return $this->whitelist->belongsToExcludedNamespace($name);
29
    }
30
31
    public function isFunctionInternal(string $name): bool
32
    {
33
        return $this->reflector->isFunctionInternal($name);
34
    }
35
36
    public function isClassInternal(string $name): bool
37
    {
38
        return $this->reflector->isClassInternal($name);
39
    }
40
41
    public function isConstantInternal(string $name): bool
42
    {
43
        return $this->reflector->isConstantInternal($name);
44
    }
45
46
    public function isExposedClass(string $resolvedName): bool
47
    {
48
        return !$this->whitelist->belongsToExcludedNamespace($resolvedName)
49
            && (
50
                $this->whitelist->isExposedClassFromGlobalNamespace($resolvedName)
51
                || $this->whitelist->isSymbolExposed($resolvedName)
52
            );
53
    }
54
55
    public function isExposedConstant(string $name): bool
56
    {
57
        // Special case: internal constants must be treated as exposed symbols.
58
        //
59
        // Example: when declaring a new internal constant for compatibility
60
        // reasons, it must remain un-prefixed.
61
        return $this->reflector->isConstantInternal($name)
62
            || $this->whitelist->isExposedConstantFromGlobalNamespace($name)
63
            || $this->whitelist->isSymbolExposed($name, true);
64
    }
65
}
66