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.
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.
Import use statements should not be declared with a leading backslash and doing so is discouraged by PHP itself:
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.