Skip to content

Commit 79b2b4e

Browse files
fix: Fix aliasing functions with multiple-level namespaces (#1061)
--------- Co-authored-by: Théo FIDRY <[email protected]>
1 parent 5d3fda6 commit 79b2b4e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Autoload/ScoperAutoloadGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private static function groupFunctionsByNamespace(array $exposedFunctions): arra
306306
$originalFQ = new FullyQualified($exposed);
307307

308308
$namespace = $originalFQ->slice(0, -1);
309-
$functionName = null === $namespace ? $exposed : (string) $originalFQ->slice(1);
309+
$functionName = null === $namespace ? $exposed : (string) $originalFQ->slice(-1, 1);
310310

311311
$groupedFunctions[(string) $namespace][] = [$exposed, $functionName, $prefix];
312312
}

tests/Autoload/ScoperAutoloadGeneratorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ public static function provideRegistry(): iterable
188188
['Acme\bar', 'Humbug\Acme\bar'],
189189
['Acme\foo', 'Humbug\Acme\foo'],
190190
['Emca\baz', 'Humbug\Emca\baz'],
191+
['Acme\Emca\foo', 'Humbug\Acme\Emca\foo'],
191192
],
192193
),
193194
[],
@@ -218,6 +219,10 @@ public static function provideRegistry(): iterable
218219
219220
// Function aliases. For more information see:
220221
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
222+
namespace Acme\Emca {
223+
if (!function_exists('Acme\Emca\foo')) { function foo() { return \Humbug\Acme\Emca\foo(...func_get_args()); } }
224+
}
225+
221226
namespace Acme {
222227
if (!function_exists('Acme\bar')) { function bar() { return \Humbug\Acme\bar(...func_get_args()); } }
223228
if (!function_exists('Acme\foo')) { function foo() { return \Humbug\Acme\foo(...func_get_args()); } }

0 commit comments

Comments
 (0)