1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Humbug\PhpScoper\Symbol; |
6
|
|
|
|
7
|
|
|
use Humbug\PhpScoper\Configuration\SymbolsConfiguration; |
8
|
|
|
use Humbug\PhpScoper\Reflector; |
9
|
|
|
use PhpParser\Node\Name; |
10
|
|
|
use PhpParser\Node\Name\FullyQualified; |
11
|
|
|
use function strpos; |
12
|
|
|
|
13
|
|
|
final class EnrichedReflector |
14
|
|
|
{ |
15
|
|
|
private SymbolsConfiguration $configuration; |
16
|
|
|
private Reflector $reflector; |
17
|
|
|
|
18
|
|
|
public function __construct( |
19
|
|
|
SymbolsConfiguration $configuration, |
20
|
|
|
Reflector $reflector |
21
|
|
|
) { |
22
|
|
|
$this->configuration = $configuration; |
23
|
|
|
$this->reflector = $reflector; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function belongsToExcludedNamespace(string $name): bool |
27
|
|
|
{ |
28
|
|
|
return $this->configuration->getExcludedNamespaces()->belongsToRegisteredNamespace($name); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function isExcludedNamespace(string $name): bool |
32
|
|
|
{ |
33
|
|
|
return $this->configuration->getExcludedNamespaces()->isRegisteredNamespace($name); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function belongsToExposedNamespace(string $name): bool |
37
|
|
|
{ |
38
|
|
|
return $this->configuration->getExposedNamespaces()->belongsToRegisteredNamespace($name); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function isExposedNamespace(string $name): bool |
42
|
|
|
{ |
43
|
|
|
return $this->configuration->getExposedNamespaces()->isRegisteredNamespace($name); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function isExposedFunctionFromGlobalNamespace(string $functionName): bool |
47
|
|
|
{ |
48
|
|
|
return $this->configuration->shouldExposeGlobalFunctions() && false === strpos($functionName, '\\'); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function isExposedConstantFromGlobalNamespace(string $constantName): bool |
52
|
|
|
{ |
53
|
|
|
return $this->configuration->shouldExposeGlobalConstants() && false === strpos($constantName, '\\'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function isExposedClassFromGlobalNamespace(string $className): bool |
57
|
|
|
{ |
58
|
|
|
return $this->configuration->shouldExposeGlobalClasses() && false === strpos($className, '\\'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function isInternalFunction(string $name): bool |
62
|
|
|
{ |
63
|
|
|
return $this->reflector->isFunctionInternal($name); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function isExposedFunction(FullyQualified $name): bool |
67
|
|
|
{ |
68
|
|
|
$nameString = (string) $name; |
69
|
|
|
|
70
|
|
|
return ( |
71
|
|
|
!$this->reflector->isFunctionInternal($nameString) |
72
|
|
|
&& ( |
73
|
|
|
$this->isExposedFunctionFromGlobalNamespace($nameString) |
74
|
|
|
|| $this->isSymbolExposed($nameString) |
75
|
|
|
) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function isInternalClass(string $name): bool |
80
|
|
|
{ |
81
|
|
|
return $this->reflector->isClassInternal($name); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function isExposedClass(FullyQualified $name): bool |
85
|
|
|
{ |
86
|
|
|
$nameString = (string) $name; |
87
|
|
|
|
88
|
|
|
return $this->isExposedClassFromGlobalNamespace($nameString) |
89
|
|
|
|| $this->isSymbolExposed($nameString); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function isInternalConstant(string $name): bool |
93
|
|
|
{ |
94
|
|
|
return $this->reflector->isConstantInternal($name); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function isExposedConstant(string $name): bool |
98
|
|
|
{ |
99
|
|
|
return !$this->reflector->isConstantInternal($name) |
100
|
|
|
&& $this->isSymbolExposed($name, true) |
101
|
|
|
&& $this->isExposedConstantFromGlobalNamespace($name); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function isSymbolExposed(string $name, bool $constant = false): bool |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
return true; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.