@@ -61,6 +61,7 @@ public function generate(): string
6161 {
6262 $ n = self ::$ eol ;
6363 $ result = '<?php ' . $ n
64+ . '/** @noinspection ALL */ ' . $ n . $ n
6465 . '// @codingStandardsIgnoreFile ' . $ n . $ n ;
6566
6667 $ parser = $ this ->getParser ();
@@ -74,7 +75,7 @@ public function generate(): string
7475 $ isGlobalNamespace = $ namespace === '' ;
7576 $ result .= 'namespace ' . (!$ isGlobalNamespace ? ' ' . $ namespace : '' ) . $ n
7677 . '{ ' . $ n ;
77- $ result .= $ this ->formatAliases (
78+ $ result .= $ this ->formatNamespaceAliases (
7879 $ parser ->getAliases ($ class ->getName (), ParserInterface::TYPE_CLASS )
7980 );
8081 $ result .= $ n
@@ -91,7 +92,7 @@ public function generate(): string
9192 $ isGlobalNamespace = ($ namespace === '' );
9293 $ result .= 'namespace ' . (!$ isGlobalNamespace ? ' ' . $ namespace : '' ) . $ n
9394 . '{ ' . $ n ;
94- $ result .= $ this ->formatAliases (
95+ $ result .= $ this ->formatNamespaceAliases (
9596 $ parser ->getAliases ($ function ->getName (), ParserInterface::TYPE_FUNCTION )
9697 );
9798 $ result .= $ n
@@ -107,13 +108,22 @@ public function generate(): string
107108 * @param array $aliases
108109 * @return string
109110 */
110- protected function formatAliases (array $ aliases ): string
111+ protected function formatNamespaceAliases (array $ aliases ): string
111112 {
112113 $ n = self ::$ eol ;
113114 $ t = self ::$ tab ;
114115
115116 $ result = '' ;
116117 foreach ($ aliases as $ fullName => $ alias ) {
118+ // todo: can be removed when this pull request is confirmed and tagged
119+ // https://github.com/goaop/parser-reflection/pull/96
120+ if ($ alias === null ) {
121+ \preg_match ('~ \\\\?(?P<last>[^ \\\\]+)$~ ' , $ fullName , $ matches );
122+ $ alias = $ matches ['last ' ] ?? $ fullName ;
123+ } else {
124+ $ alias = (string ) $ alias ;
125+ }
126+
117127 $ result .= $ t . 'use ' . $ fullName ;
118128 if ($ alias !== \substr ($ fullName , -\strlen ($ alias ))) {
119129 $ result .= ' as ' . $ alias ;
0 commit comments