Problem/Motivation
The latest version of coder tries to fix nullable function parameters (introduced in PHP 7.4) into a ternary expression that will break classes. Additionally (possibly a separate issue) it would be great if the @var tag could be omitted in this case when it adds no extra value.
/**
* The cursor that results were fetched before.
*
* @var string|null
*/
protected ?string $before = NULL;
FILE: ...g/modules/custom/social_graphql/src/GraphQL/EntityConnection.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
56 | ERROR | [x] Expected 1 space after "?"; 0 found
| | (Squiz.WhiteSpace.OperatorSpacing.NoSpaceAfter)
56 | ERROR | [ ] Missing member variable doc comment
| | (Drupal.Commenting.VariableComment.Missing)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
This currently prevents private modules for which we know there will be PHP 7.4 support from being linted by coder.
Removing the @var string|null statement from the block does not actually change the detected errors. (The line number change to keep pointing at the protected variable statement)
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Comments
Comment #2
kingdutchComment #3
kingdutchI wasn't awake when titling this issue apparently.
Comment #4
arkener commentedI can't seem to reproduce this issue on the latest version of coder with the following example:
The stated issue seems to be caused by a rule which is provided by the Squiz ruleset. Could you check which codesniffer version you're running using
composer show squizlabs/php_codesniffer?The property @var rule can be omitted by creating a configuration file and excluding the missing var comment rule using:
Comment #5
kingdutchIt looks like this was indeed caused by an old version (though I no longer know what version I was using). I can also no longer replicate this with the latest version (3.6.0 at time of writing).
I suspect I may have been using something older than 3.5.0 in which this was released.