Skip to content

LineLength too strict for PHP8 namespaces #1365

@rjd22

Description

@rjd22

Describe the enhancement

As of PHP8, namespaces are considered as a single token (https://wiki.php.net/rfc/namespaced_names_as_token).

Therefore it is now impossible to do:

use Name\Space
\Class;

When the namespace is too long, and exceeds the LineLength limit, PHPCS raises an error on the lign being too long.

From PHP8, the LineLength should not apply to import statements.

Code sample

# file 1
namespace A\Very\Extremely\Long\And\Ridiculous\Namespace;
class ThisIsAVeryPreciseAndSinglePurposeClassWithAVeryLongName {}

# file 2

namespace My\Other\Namespace

use A\Very\Extremely\Long\And\Ridiculous\Namespace\ThisIsAVeryPreciseAndSinglePurposeClassWithAVeryLongName;

class SimpleClass{}

To reproduce

Steps to reproduce the behavior:

Create 2 files with the above content
Run `phpcs test.php` ...

Describe the solution you'd like

I've took a stap at this previously but didn't have time to continue on it and also wanted to wait out the phpcs 4.0 release. I'm willing to do the work to fix this but would like to discuss what the most preferred way so solve this would be.

My goal to to avoid users having to add phpcs:ignore tags for long use statements and to improve the developer experience.

Additional context (optional)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions