Skip to content

Commit

Permalink
Support string class_alias calls with leading backslash
Browse files Browse the repository at this point in the history
Fixes #3465
  • Loading branch information
muglug committed May 27, 2020
1 parent ef53ee3 commit b9ea115
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,14 @@ private function registerClassMapFunctionCall(
}

if ($first_arg_value !== null && $second_arg_value !== null) {
if ($first_arg_value[0] === '\\') {
$first_arg_value = substr($first_arg_value, 1);
}

if ($second_arg_value[0] === '\\') {
$second_arg_value = substr($second_arg_value, 1);
}

$second_arg_value = strtolower($second_arg_value);

$this->codebase->classlikes->addClassAlias(
Expand Down
25 changes: 25 additions & 0 deletions tests/TryCatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,31 @@ class_alias(
namespace Client;
try {
throw new \Alias\UserException\UserExceptionAlias();
} catch (\Alias\UserException\UserExceptionAlias $e) {
// do nothing
}'
],
'aliasAnotherException' => [
'<?php
namespace UserException;
class UserException extends \Exception {
}
namespace Alias\UserException;
use function class_alias;
class_alias(
\UserException\UserException::class,
\'\Alias\UserException\UserExceptionAlias\'
);
namespace Client;
try {
throw new \Alias\UserException\UserExceptionAlias();
} catch (\Alias\UserException\UserExceptionAlias $e) {
Expand Down

0 comments on commit b9ea115

Please sign in to comment.