Skip to content

Local type aliases #460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
Apr 18, 2021
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e90d916
type aliases: extract TypeAliasResolver
jiripudil Dec 30, 2020
1cf6303
type aliases: add test
jiripudil Feb 27, 2021
72154c9
type aliases: support class-scoped local aliases
jiripudil Feb 27, 2021
f54f80e
type aliases: add test for nested aliases
jiripudil Feb 27, 2021
293d9b3
type aliases: support type alias imports
jiripudil Feb 27, 2021
390cb96
fix cs and phpstan baseline
jiripudil Feb 27, 2021
a4e48fe
Correct prefix priority
ondrejmirtes Feb 28, 2021
9ed65cc
type aliases: resolve type aliases lazily and in correct NameScope
jiripudil Mar 27, 2021
de4ff0c
type aliases: remove __set_state from PhpDoc\Tag classes as they are …
jiripudil Mar 27, 2021
b8941b6
type aliases: add TemplateTypeCheck tests for local aliases
jiripudil Mar 27, 2021
7f066e5
type aliases: keep the TypeNode already resolved by phpdoc-parser
jiripudil Apr 11, 2021
3519a52
type aliases: report invalid alias definitions via a Rule instead of …
jiripudil Apr 15, 2021
a5ea824
Microoptimization
ondrejmirtes Apr 18, 2021
ce5a49a
resolvingClassTypeAliases should be unset here as well
ondrejmirtes Apr 18, 2021
e2cfe20
fix LocalTypeAliasesRule registration
jiripudil Apr 18, 2021
ec36298
remove obsolete data provider
jiripudil Apr 18, 2021
1070463
Allow type aliases to be bypassed in SignatureMapParser
ondrejmirtes Apr 18, 2021
4fc1534
Fix LocalTypeAliasesRule
ondrejmirtes Apr 18, 2021
22eb90a
LocalTypeAliasesRuleTest does not require static reflection
ondrejmirtes Apr 18, 2021
b3fa374
treat TypeAliasImportTag::$importedFrom as a class name string
jiripudil Apr 18, 2021
c8f3f4f
resolve TypeAliasImportTag::$importedFrom in the name scope when reso…
jiripudil Apr 18, 2021
25013e6
Resolve type aliases directly in resolveIdentifierTypeNode, not throu…
ondrejmirtes Apr 18, 2021
334960c
Bump memory limit for tests-fast-static-reflection a bit
ondrejmirtes Apr 18, 2021
9a8738d
Microoptimization
ondrejmirtes Apr 18, 2021
31ea9a2
Regression test
ondrejmirtes Apr 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/Type/TypeAliasResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ private function resolveLocalTypeAlias(string $aliasName, NameScope $nameScope):
return null;
}

$aliasNameInClassScope = $className . '::' . $aliasName;

if (array_key_exists($aliasNameInClassScope, $this->resolvedLocalTypeAliases)) {
return $this->resolvedLocalTypeAliases[$aliasNameInClassScope];
}

// prevent infinite recursion
if (array_key_exists($className, $this->resolvingClassTypeAliases)) {
return null;
Expand All @@ -98,12 +104,6 @@ private function resolveLocalTypeAlias(string $aliasName, NameScope $nameScope):
return null;
}

$aliasNameInClassScope = $className . '::' . $aliasName;

if (array_key_exists($aliasNameInClassScope, $this->resolvedLocalTypeAliases)) {
return $this->resolvedLocalTypeAliases[$aliasNameInClassScope];
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this fine? @jiripudil

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks fine.

if ($this->reflectionProvider->hasClass($nameScope->resolveStringName($aliasName))) {
return null;
}
Expand Down