Skip to content

Commit 8457fd6

Browse files
committed
Generic/DisallowYodaConditions: add code coverage ignore annotation
This commit adds the `@codeCoverageIgnoreStart/@codeCoverageIgnoreEnd` PHPUnit annotations to ignore, for the purposes of code coverage, a line that can't be tested. I considered doing this initially when I worked on improving code coverage for this sniff in PHPCSStandards#465, but I wrongly assumed that was not an option due to the `Squiz.Commenting.InlineComment.InvalidEndChar` error (which is part of the standard used by PHPCS). What I failed to notice back then is that I was adding the annotation below a comment, and this triggers the error: ``` // Shouldn't be possible but may happen if external sniffs are using this method. // @codeCoverageIgnoreStart ``` Adding the annotation before the comment as it is done in this commit does not trigger the error because the `Squiz.Commenting.InlineComment` sniff will only trigger the `InvalidEndChar` error if the first character of the comment is a letter. Using `return true; // @codeCoverageIgnore` is not an option because it triggers `Squiz.Commenting.PostStatementComment.Found`.
1 parent df258d4 commit 8457fd6

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/Standards/Generic/Sniffs/ControlStructures/DisallowYodaConditionsSniff.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,10 @@ public function isArrayStatic(File $phpcsFile, $arrayToken)
145145
$start = $tokens[$arrayToken]['parenthesis_opener'];
146146
$end = $tokens[$arrayToken]['parenthesis_closer'];
147147
} else {
148+
// @codeCoverageIgnoreStart
148149
// Shouldn't be possible but may happen if external sniffs are using this method.
149150
return true;
151+
// @codeCoverageIgnoreEnd
150152
}
151153

152154
$staticTokens = Tokens::$emptyTokens;

0 commit comments

Comments
 (0)