-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squiz/ClosingDeclarationCommentSniff: prevent non-problematic bug
This commit fixes a non-problematic bug on line 96. The code `if (rtrim($tokens[$next]['content']) === $comment)` was not taking into account that `$next` can be false. To fix it, a `$next !== false` check was added to the if condition. This problem did not cause any issues because when `$next` is `false`, the code would check the content of the first token (`$tokens[0]['content']`) and this token can only be the PHP open tag or inline HTML. The code would only produce false positives if the content of the first token would be `// end ...` which is unlikely and would be invalid HTML. A test was added exercising the code path where `$next` is `false`. And another tests which actually hits the bug and safeguards against potential regressions for the non-problematic bug fix.
- Loading branch information
1 parent
579f081
commit 5b597d8
Showing
6 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.4.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
// This should be the only test in this file. | ||
// Testing that the sniff is triggered when the closing bracket is | ||
// the last character in the file (no newline after it). | ||
|
||
function closingBraceAtEndOfFile() { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.4.inc.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
// This should be the only test in this file. | ||
// Testing that the sniff is triggered when the closing bracket is | ||
// the last character in the file (no newline after it). | ||
|
||
function closingBraceAtEndOfFile() { | ||
}//end closingBraceAtEndOfFile() |
11 changes: 11 additions & 0 deletions
11
src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.5.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//end closingBraceAtEndOfFileMissingComment() | ||
|
||
<?php | ||
|
||
// This should be the only test in this file. | ||
// Testing that the sniff is triggered and the fixer works when the closing bracket is | ||
// the last character in the file (no newline after it) and the content of the first token | ||
// is a "//end closingBraceAtEndOfFileMissingComment()" comment. | ||
|
||
function closingBraceAtEndOfFileMissingComment() { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Standards/Squiz/Tests/Commenting/ClosingDeclarationCommentUnitTest.5.inc.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//end closingBraceAtEndOfFileMissingComment() | ||
|
||
<?php | ||
|
||
// This should be the only test in this file. | ||
// Testing that the sniff is triggered and the fixer works when the closing bracket is | ||
// the last character in the file (no newline after it) and the content of the first token | ||
// is a "//end closingBraceAtEndOfFileMissingComment()" comment. | ||
|
||
function closingBraceAtEndOfFileMissingComment() { | ||
}//end closingBraceAtEndOfFileMissingComment() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters