Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
ChangeEnumerator | |
0.00% |
0 / 27 |
|
0.00% |
0 / 2 |
156 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
determineReplacements | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
132 |
1 | <?php |
2 | |
3 | namespace BrianHenryIE\Strauss; |
4 | |
5 | use BrianHenryIE\Strauss\Composer\Extra\StraussConfig; |
6 | use BrianHenryIE\Strauss\Types\ClassSymbol; |
7 | use BrianHenryIE\Strauss\Types\NamespaceSymbol; |
8 | |
9 | class ChangeEnumerator |
10 | { |
11 | protected StraussConfig $config; |
12 | protected string $workingDir; |
13 | |
14 | public function __construct(StraussConfig $config, string $workingDir) |
15 | { |
16 | $this->config = $config; |
17 | $this->workingDir = $workingDir; |
18 | |
19 | $absoluteTargetDir = $workingDir . $config->getTargetDirectory(); |
20 | } |
21 | |
22 | public function determineReplacements(DiscoveredSymbols $discoveredSymbols): void |
23 | { |
24 | foreach ($discoveredSymbols->getSymbols() as $symbol) { |
25 | if (in_array( |
26 | $symbol->getFile()->getDependency()->getPackageName(), |
27 | $this->config->getExcludePackagesFromPrefixing(), |
28 | true |
29 | ) |
30 | ) { |
31 | continue; |
32 | } |
33 | |
34 | foreach ($this->config->getExcludeFilePatternsFromPrefixing() as $excludeFilePattern) { |
35 | if (1 === preg_match($excludeFilePattern, $symbol->getFile()->getTargetRelativePath())) { |
36 | continue 2; |
37 | } |
38 | } |
39 | |
40 | if ($symbol instanceof NamespaceSymbol) { |
41 | // Don't double-prefix namespaces. |
42 | if (str_starts_with($symbol->getOriginalSymbol(), $this->config->getNamespacePrefix())) { |
43 | continue; |
44 | } |
45 | |
46 | foreach ($this->config->getNamespaceReplacementPatterns() as $namespaceReplacementPattern => $replacement) { |
47 | $prefixed = preg_replace($namespaceReplacementPattern, $replacement, $symbol->getOriginalSymbol()); |
48 | |
49 | if ($prefixed !== $symbol->getOriginalSymbol()) { |
50 | $symbol->setReplacement($prefixed); |
51 | continue 2; |
52 | } |
53 | } |
54 | |
55 | $prefixed = "{$this->config->getNamespacePrefix()}\\{$symbol->getOriginalSymbol()}"; |
56 | $symbol->setReplacement($prefixed); |
57 | } |
58 | |
59 | if ($symbol instanceof ClassSymbol) { |
60 | // Don't double-prefix classnames. |
61 | if (str_starts_with($symbol->getOriginalSymbol(), $this->config->getClassmapPrefix())) { |
62 | continue; |
63 | } |
64 | |
65 | $symbol->setReplacement($this->config->getClassmapPrefix() . $symbol->getOriginalSymbol()); |
66 | } |
67 | } |
68 | } |
69 | } |