Skip to content

Commit

Permalink
Calculate original unprefixed namespaces when running repeatedly
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianHenryIE committed Nov 23, 2023
1 parent 04d727a commit db99ef9
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/ChangeEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ public function __construct(StraussConfig $config)
*/
public function getDiscoveredNamespaces(?string $namespacePrefix = ''): array
{
$discoveredNamespaceReplacements = array_filter(
$this->discoveredNamespaces,
function (string $replacement) use ($namespacePrefix) {
return empty($namespacePrefix) || ! str_starts_with($replacement, $namespacePrefix);
},
ARRAY_FILTER_USE_KEY
);
$discoveredNamespaceReplacements = [];

// When running subsequent times, try to discover the original namespaces.
// This is naive: it will not work where namespace replacement patterns have been used.
foreach ($this->discoveredNamespaces as $key => $value) {
$unprefixed = str_starts_with($this->namespacePrefix, $key)
? ltrim(substr($key, strlen($this->namespacePrefix)), '\\')
: $key;
$discoveredNamespaceReplacements[ $unprefixed ] = $value;
}

uksort($discoveredNamespaceReplacements, function ($a, $b) {
return strlen($a) <=> strlen($b);
Expand Down

0 comments on commit db99ef9

Please sign in to comment.