Skip to content

Commit

Permalink
fix: Fix aliasing functions with multiple-level namespaces (#1061)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Théo FIDRY <[email protected]>
  • Loading branch information
VincentLanglet and theofidry authored Sep 2, 2024
1 parent 5d3fda6 commit 79b2b4e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Autoload/ScoperAutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private static function groupFunctionsByNamespace(array $exposedFunctions): arra
$originalFQ = new FullyQualified($exposed);

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

$groupedFunctions[(string) $namespace][] = [$exposed, $functionName, $prefix];
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Autoload/ScoperAutoloadGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public static function provideRegistry(): iterable
['Acme\bar', 'Humbug\Acme\bar'],
['Acme\foo', 'Humbug\Acme\foo'],
['Emca\baz', 'Humbug\Emca\baz'],
['Acme\Emca\foo', 'Humbug\Acme\Emca\foo'],
],
),
[],
Expand Down Expand Up @@ -218,6 +219,10 @@ public static function provideRegistry(): iterable
// Function aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
namespace Acme\Emca {
if (!function_exists('Acme\Emca\foo')) { function foo() { return \Humbug\Acme\Emca\foo(...func_get_args()); } }
}
namespace Acme {
if (!function_exists('Acme\bar')) { function bar() { return \Humbug\Acme\bar(...func_get_args()); } }
if (!function_exists('Acme\foo')) { function foo() { return \Humbug\Acme\foo(...func_get_args()); } }
Expand Down

0 comments on commit 79b2b4e

Please sign in to comment.