-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squiz/EmbeddedPhp: fix false positive when handling short open tags
The content of a PHP long open tag token is `<?php ` (note the space after the tag). The content of a PHP short open tag is `<?` (no space after the tag). The sniff did not account correctly for this difference when checking the expected number of spaces after a short open tag, resulting in false positives and incorrect fixes. For example, the code below: ``` <? echo 'one space after short open tag'; ?> ``` Resulted in the error (there is just one space after the opening tag and not two, as stated in the error): ``` Expected 1 space after opening PHP tag; 2 found (Squiz.PHP.EmbeddedPhp.SpacingAfterOpen) ``` And the incorrect fix: ``` <?echo 'without space after short open tag'; ?> ``` This commit fixes this problem by changing the sniff code to consider that only long open tags contain a space after the tag in the `content` key of the token array.
- Loading branch information
1 parent
c76678a
commit 0ed5577
Showing
6 changed files
with
78 additions
and
4 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
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
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
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,25 @@ | ||
<? | ||
|
||
// This test case file MUST always start with a open PHP tag set (with this comment) to prevent | ||
// the tests running into the "first PHP open tag excepted" condition breaking the tests. | ||
// Tests related to that "first PHP open tag excepted" condition should go in separate files. | ||
|
||
// This test case file only deals with SHORT OPEN TAGS. | ||
|
||
?> | ||
|
||
<? | ||
/* Contrary to the long open tag token, the short open tag token does not contain a space after the | ||
tag and the sniff should handle it accordingly. The test below protects against regressions | ||
related to https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/588. */ | ||
?> | ||
<? echo 'one space after short open tag'; ?> | ||
|
||
<? echo 'two spaces after short open tag'; ?> | ||
|
||
<?echo 'without space after short open tag'; ?> | ||
|
||
<? | ||
// This test case file MUST always end with an unclosed open PHP tag (with this comment) to prevent | ||
// the tests running into the "last PHP closing tag excepted" condition breaking tests. | ||
// Tests related to that "last PHP closing tag excepted" condition should go in separate files. |
25 changes: 25 additions & 0 deletions
25
src/Standards/Squiz/Tests/PHP/EmbeddedPhpUnitTest.24.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,25 @@ | ||
<? | ||
|
||
// This test case file MUST always start with a open PHP tag set (with this comment) to prevent | ||
// the tests running into the "first PHP open tag excepted" condition breaking the tests. | ||
// Tests related to that "first PHP open tag excepted" condition should go in separate files. | ||
|
||
// This test case file only deals with SHORT OPEN TAGS. | ||
|
||
?> | ||
|
||
<? | ||
/* Contrary to the long open tag token, the short open tag token does not contain a space after the | ||
tag and the sniff should handle it accordingly. The test below protects against regressions | ||
related to https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/588. */ | ||
?> | ||
<? echo 'one space after short open tag'; ?> | ||
|
||
<? echo 'two spaces after short open tag'; ?> | ||
|
||
<? echo 'without space after short open tag'; ?> | ||
|
||
<? | ||
// This test case file MUST always end with an unclosed open PHP tag (with this comment) to prevent | ||
// the tests running into the "last PHP closing tag excepted" condition breaking tests. | ||
// Tests related to that "last PHP closing tag excepted" condition should go in separate files. |
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