-
-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor importByParent method to use existing import infrastructure #3
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
Changes from 6 commits
c4da6bf
ae89c32
fb3a2f4
0db4efd
e31cae7
98a1925
247aba6
b7827b6
14cdb20
93d2176
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -204,6 +204,30 @@ public function import(FullyQualified | FunctionName | string $fqcnOrEnum) : str | |
| return $alias; | ||
| } | ||
|
|
||
| /** | ||
| * Imports a class by importing its parent namespace and returning the relative path | ||
| */ | ||
| public function importByParent(FullyQualified | string $name) : string | ||
| { | ||
| $fqcn = FullyQualified::maybeFromString($name); | ||
|
|
||
| // If there's no namespace, just return the class name | ||
| if ($fqcn->namespace === null) { | ||
| return (string) $fqcn->className; | ||
| } | ||
|
|
||
| // Check if the full target namespace is the same as the current namespace | ||
| if ($this->namespace !== null && $fqcn->namespace->equals($this->namespace)) { | ||
| return (string) $fqcn->className; | ||
| } | ||
|
|
||
| // Import the namespace and return the alias with class name | ||
| $namespaceAlias = $this->findAvailableAlias($fqcn->namespace, $fqcn->namespace->lastPart); | ||
| $this->imports[$namespaceAlias] = $fqcn->namespace; | ||
|
|
||
| return $namespaceAlias . '\\' . (string) $fqcn->className; | ||
|
||
| } | ||
|
|
||
| /** | ||
| * Generates a PHP attribute string for the given fully qualified class name | ||
| */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use explicit boolean comparison
=== trueas suggested. Fixed in commit b7827b6.