You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
On a method with a PHP 8 attribute before a nullable parameter, cs if forcing to have a space after the ? of a nullable the nullable parameter
Create a file called test.php with the code sample above...
Run phpcs test.php ...
See error message displayed
451 | ERROR | [x] Expected at least 1 space after "?"; 0 found
| | (PSR12.Operators.OperatorSpacing.NoSpaceAfter)
451 | ERROR | [x] Parameter $value has null default value, but is not marked as nullable.
| | (SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue.NullabilityTypeMissing)
Expected behavior
We should be able to put a nullable parameter after a PHP 8 parameter attribute. Here cs is confusing the PHP8 attribute and the bool as a ternary operator, thus forcing the space after the "?" causing the "Parameter $value has null default value" because this work fine :
public function setDefault(#[ImportValue(
column: 'Material by default',
transformer: YesNoBooleanTransformer::class,
constraints: [
[
Assert\Type::class,
['type' => 'bool'],
],
]
)] ? bool $value): void
{
$this->setBool('default', $value);
}
Versions (please complete the following information):
@mhlsf Thank you for reporting this with a usable code sample. I've been able to reproduce this and have submitted PR #3446 to fix this. If you have the chance, testing appreciated.
gsherwood
changed the title
Confusing nullable parameter as ternary operator
Nullable parameter incorrectly tokenized as ternary operator
Oct 11, 2021
gsherwood
changed the title
Nullable parameter incorrectly tokenized as ternary operator
Nullable parameter after attribute incorrectly tokenized as ternary operator
Oct 11, 2021
Describe the bug
On a method with a PHP 8 attribute before a nullable parameter, cs if forcing to have a space after the ? of a nullable the nullable parameter
Code sample
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
We should be able to put a nullable parameter after a PHP 8 parameter attribute. Here cs is confusing the PHP8 attribute and the bool as a ternary operator, thus forcing the space after the "?" causing the "Parameter $value has null default value" because this work fine :
Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: