- Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Describe the bug
I'm getting an error when attempting to align the assignment tokens when defining constants, if one of the constants is named DEFAULT
. It's trying to align DEFAULT
with the array assignment token below, rather than the other statements directly below it.
Code sample
<?php declare(strict_types=1); // phpcs:ignore final class Test { public const DEFAULT = 'default'; public const SOS = 'sos'; public const HELP = 'help'; // phpcs:ignore protected static $thisIsAReallyLongVariableName = [ self::DEFAULT => 'DEFAULT', self::SOS => 'SOS', self::HELP => 'Help', ]; }
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php ...
- See error message displayed
8 | ERROR | [x] Equals sign not aligned with surrounding | | assignments; expected 28 spaces but found 1 | | space | | (Generic.Formatting.MultipleStatementAlignment.NotSame) 9 | ERROR | [x] Equals sign not aligned with surrounding | | assignments; expected 2 spaces but found 5 | | spaces | | (Generic.Formatting.MultipleStatementAlignment.NotSame) 10 | ERROR | [x] Equals sign not aligned with surrounding | | assignments; expected 1 space but found 4 | | spaces | | (Generic.Formatting.MultipleStatementAlignment.NotSame)
Expected behavior
No reported errors.
Versions (please complete the following information):
- OS: Ubuntu 20.10
- PHP: 7.4
- PHPCS: 3.6.0
- Standard: PSR2
Additional context
To clarify the issue, this throws no errors:
<?php declare(strict_types=1); // phpcs:ignore final class Test { public const DEFAULT = 'default'; public const SOS = 'sos'; public const HELP = 'help'; // phpcs:ignore protected static $thisIsAReallyLongVariableName = [ self::DEFAULT => 'DEFAULT', self::SOS => 'SOS', self::HELP => 'Help', ]; }
This also throws no errors:
<?php declare(strict_types=1); // phpcs:ignore final class Test { public const DEFAULX = 'default'; public const SOS = 'sos'; public const HELP = 'help'; // phpcs:ignore protected static $thisIsAReallyLongVariableName = [ self::DEFAULX => 'DEFAULT', self::SOS => 'SOS', self::HELP => 'Help', ]; }