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

Commits on May 10, 2024

  1. UseStatements::splitImportUseStatement(): improve handling of leading…

    … 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 committed May 10, 2024
    Configuration menu
    Copy the full SHA
    f7e6542 View commit details
    Browse the repository at this point in the history