This PR improves code coverage for the Generic.ControlStructures.DisallowYodaConditions sniff. It adds a few tests for uncovered lines and documents using tests a few comparison operators that this sniff listens for that were not part of the tests before.
Besides that, this PR removes an unused variable, fixes a typo in a code comment, removes two unreachable variables, and renames a variable to make it more clear what it contains.
It is impossible to add code coverage for the line below using the current test framework and we should not remove it as external sniffs could be using the DisallowYodaConditionsSniff::isArrayStatic() and relying on the current behavior (returning true if the passed token index is not an array):
I left a comment documenting that the line cannot be covered by tests but cannot be removed as well.
I considered using // @codeCoverageIgnore or // @codeCoverageIgnoreStart and // @codeCoverageIgnoreEnd, but that is not possible as well as those annotations trigger different sniff errors for the coding standard used by PHPCS (Squiz.Commenting.PostStatementComment.Found and Squiz.Commenting.InlineComment.InvalidEndChar). I will open a separate issue for this.
Description
This PR improves code coverage for the Generic.ControlStructures.DisallowYodaConditions sniff. It adds a few tests for uncovered lines and documents using tests a few comparison operators that this sniff listens for that were not part of the tests before.
Besides that, this PR removes an unused variable, fixes a typo in a code comment, removes two unreachable variables, and renames a variable to make it more clear what it contains.
It is impossible to add code coverage for the line below using the current test framework and we should not remove it as external sniffs could be using the
DisallowYodaConditionsSniff::isArrayStatic()
and relying on the current behavior (returningtrue
if the passed token index is not an array):https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/30b3148b302aaba28d72bdb2432b144ff9d47751/src/Standards/Generic/Sniffs/ControlStructures/DisallowYodaConditionsSniff.php#L152
I left a comment documenting that the line cannot be covered by tests but cannot be removed as well.
I considered using
// @codeCoverageIgnore
or// @codeCoverageIgnoreStart
and// @codeCoverageIgnoreEnd
, but that is not possible as well as those annotations trigger different sniff errors for the coding standard used by PHPCS (Squiz.Commenting.PostStatementComment.Found
andSquiz.Commenting.InlineComment.InvalidEndChar
). I will open a separate issue for this.Related issues/external references
Part of https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/146
Types of changes
PR checklist