1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Humbug\PhpScoper\Symbol; |
6
|
|
|
|
7
|
|
|
use function array_pop; |
8
|
|
|
use function array_unique; |
9
|
|
|
use function explode; |
10
|
|
|
use function implode; |
11
|
|
|
use function ltrim; |
12
|
|
|
use function Safe\preg_match; |
13
|
|
|
use function Safe\substr; |
14
|
|
|
use function strpos; |
15
|
|
|
use function strtolower; |
16
|
|
|
|
17
|
|
|
final class NamespaceRegistry |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var list<string> |
|
|
|
|
21
|
|
|
*/ |
22
|
|
|
private array $namespaceRegexes; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var list<string> |
26
|
|
|
*/ |
27
|
|
|
private array $namespaceNames; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string[] $namespaceRegexes |
31
|
|
|
* @param string[] $namespaceNames |
32
|
|
|
*/ |
33
|
|
|
public static function create( |
34
|
|
|
array $namespaceRegexes = [], |
35
|
|
|
array $namespaceNames = [] |
36
|
|
|
): self { |
37
|
|
|
return new self( |
38
|
|
|
array_unique($namespaceRegexes), |
39
|
|
|
array_unique($namespaceNames), |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param list<string> $namespaceRegexes |
45
|
|
|
* @param list<string> $namespaceNames |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
array $namespaceRegexes, |
49
|
|
|
array $namespaceNames |
50
|
|
|
) { |
51
|
|
|
$this->namespaceRegexes = $namespaceRegexes; |
|
|
|
|
52
|
|
|
$this->namespaceNames = $namespaceNames; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function belongsToRegisteredNamespace(string $name): bool |
56
|
|
|
{ |
57
|
|
|
return $this->isRegisteredNamespace( |
58
|
|
|
self::extractNameNamespace($name), |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function isRegisteredNamespace(string $name): bool |
63
|
|
|
{ |
64
|
|
|
$name = strtolower(ltrim($name, '\\')); |
65
|
|
|
|
66
|
|
|
foreach ($this->namespaceNames as $excludedNamespaceName) { |
67
|
|
|
if ('' === $excludedNamespaceName) { |
68
|
|
|
return true; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if (0 !== strpos($name, $excludedNamespaceName)) { |
72
|
|
|
continue; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$nameParts = explode('\\', $name); |
76
|
|
|
|
77
|
|
|
foreach (explode('\\', $excludedNamespaceName) as $index => $excludedNamespacePart) { |
78
|
|
|
if ($nameParts[$index] !== $excludedNamespacePart) { |
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return true; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
foreach ($this->namespaceRegexes as $excludedNamespace) { |
87
|
|
|
if (preg_match($excludedNamespace, $name)) { |
88
|
|
|
return true; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return false; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
private static function extractNameNamespace(string $name): string |
96
|
|
|
{ |
97
|
|
|
$name = strtolower($name); |
98
|
|
|
|
99
|
|
|
if (0 === strpos($name, '\\')) { |
100
|
|
|
$name = substr($name, 1); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$nameParts = explode('\\', $name); |
104
|
|
|
|
105
|
|
|
array_pop($nameParts); |
106
|
|
|
|
107
|
|
|
return [] === $nameParts ? '' : implode('\\', $nameParts); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths