PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

LineLength too strict for PHP8 namespaces

Open TristanPouliquen opened this issue 2 years ago • 1 comments

Describe the bug 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:

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

Expected behavior A clear and concise description of what you expected to happen.

Versions (please complete the following information):

  • OS: Linux
  • PHP: ^8
  • PHPCS: ^1.6
  • Standard: Generic

TristanPouliquen avatar Jun 08 '22 16:06 TristanPouliquen

In the interest of helping the maintainers of this project, could I argue the case that this is a non-issue and should be closed.

Everything you write is accurate but – given how overwhelmed this project is with ageing issues and unassigned PRs – I believe the appropriate solution is that you either suppress the warning with a comment or increase the maxLineLength property in your own config.

The issue you describe only affects a curious intersection of the community: Developers who believe in coding standards enough to use CodeSniffer but have simultaneously decided to structure their code in such a way to have ended up with an 80-character import statement. Even in your own description you admit your 7-folder deep namespace with a 56 character filename is a tad ridiculous 😄 Now I'm not saying an 80-character import statement is automatic evidence of a bad decision, there are always exceptions, but I am saying it is a rare edge case and edge cases are exactly why the option to ignore certain standards exists.

So please understand I am not disagreeing with the principle. If this project was making millions in profit I would be arguing that it should support edge cases like this. But the reality is the CodeSniffer project is free and the maintainers (only 14 people with >10 commits) seem a bit overwhelmed with issues (257 issues and 106 PRs at time of writing) some of which affect many thousands more.

I personally worry the project might be at risk of collapsing if we, the developers who rely on this valuable resource, don't exercise restraint when choosing whether or not to raise an issues.

I do not represent the maintainers, this is all my own opinion. I'm just hoping that with my input, a few low-priority requests can be closed and allow some higher priority ones to get fixed. I hope you understand.

martinjoiner avatar Jul 28 '23 14:07 martinjoiner