Skip to content
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

UseStatements::splitImportUseStatement(): improve handling of leading backslash #590

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented May 10, 2024

Import use statements should not be declared with a leading backslash and doing so is discouraged by PHP itself:

Note that for namespaced names (fully qualified namespace names containing namespace separator, such as Foo\Bar as opposed to global names that do not, such as FooBar), the leading backslash is unnecessary and not recommended, as import names must be fully qualified, and are not processed relative to the current namespace.

Ref: https://www.php.net/manual/en/language.namespaces.importing.php

However, it is not a parse error to declare an import with a leading backslash. Until now, the behaviour of this method in such a case was undefined, which, in practice, meant that the leading backslash would be included in the full name.

For consistency, however, this is undesirable and makes the names found in the return value more awkward to handle by sniffs using the method.

This commit now explicitly defines the behaviour around leading backslashes in import use statements and prevents these from being included in the names in the return value.

Includes unit tests.

… backslash

Import use statements should not be declared with a leading backslash and doing so is discouraged by PHP itself:

> Note that for namespaced names (fully qualified namespace names containing namespace separator, such as `Foo\Bar` as opposed to global names that do not, such as `FooBar`), the leading backslash is unnecessary and not recommended, as import names must be fully qualified, and are not processed relative to the current namespace.

Ref: https://www.php.net/manual/en/language.namespaces.importing.php

However, it is not a parse error to declare an import with a leading backslash. Until now, the behaviour of this method in such a case was undefined, which, in practice, meant that the leading backslash would be included in the full name.

For consistency, however, this is undesirable and makes the names found in the return value more awkward to handle by sniffs using the method.

This commit now explicitly defines the behaviour around leading backslashes in import use statements and prevents these from being included in the names in the return value.

Includes unit tests.
@jrfnl jrfnl added this to the 1.0.x Next milestone May 10, 2024
@jrfnl jrfnl merged commit 567d785 into develop May 10, 2024
54 checks passed
@jrfnl jrfnl deleted the feature/usestatements-improve-handling-leading-backslash branch May 10, 2024 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant