Skip to content

Commit 92eba1c

Browse files
committed
Generic/ClosingPHPTag: also check for short open echo tag
Includes unit tests.
1 parent ae4f33b commit 92eba1c

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

package.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
664664
<file baseinstalldir="PHP/CodeSniffer" name="CharacterBeforePHPOpeningTagUnitTest.2.inc" role="test" />
665665
<file baseinstalldir="PHP/CodeSniffer" name="CharacterBeforePHPOpeningTagUnitTest.3.inc" role="test" />
666666
<file baseinstalldir="PHP/CodeSniffer" name="CharacterBeforePHPOpeningTagUnitTest.php" role="test" />
667-
<file baseinstalldir="PHP/CodeSniffer" name="ClosingPHPTagUnitTest.inc" role="test" />
667+
<file baseinstalldir="PHP/CodeSniffer" name="ClosingPHPTagUnitTest.1.inc" role="test" />
668+
<file baseinstalldir="PHP/CodeSniffer" name="ClosingPHPTagUnitTest.2.inc" role="test" />
668669
<file baseinstalldir="PHP/CodeSniffer" name="ClosingPHPTagUnitTest.php" role="test" />
669670
<file baseinstalldir="PHP/CodeSniffer" name="DeprecatedFunctionsUnitTest.inc" role="test" />
670671
<file baseinstalldir="PHP/CodeSniffer" name="DeprecatedFunctionsUnitTest.php" role="test" />

src/Standards/Generic/Sniffs/PHP/ClosingPHPTagSniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ class ClosingPHPTagSniff implements Sniff
2323
*/
2424
public function register()
2525
{
26-
return [T_OPEN_TAG];
26+
return [
27+
T_OPEN_TAG,
28+
T_OPEN_TAG_WITH_ECHO,
29+
];
2730

2831
}//end register()
2932

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?= 'foo'; ?>
2+
<b>Bold text</b>
3+
<?= 'bar'; ?>
4+
<i>Italic text</i>
5+
<?= 'baz';

src/Standards/Generic/Tests/PHP/ClosingPHPTagUnitTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ class ClosingPHPTagUnitTest extends AbstractSniffUnitTest
2121
* The key of the array should represent the line number and the value
2222
* should represent the number of errors that should occur on that line.
2323
*
24+
* @param string $testFile The name of the file being tested.
25+
*
2426
* @return array<int, int>
2527
*/
26-
public function getErrorList()
28+
public function getErrorList($testFile='')
2729
{
28-
return [9 => 1];
30+
switch ($testFile) {
31+
case 'ClosingPHPTagUnitTest.1.inc':
32+
return [9 => 1];
33+
case 'ClosingPHPTagUnitTest.2.inc':
34+
return [5 => 1];
35+
break;
36+
default:
37+
return [];
38+
break;
39+
}
2940

3041
}//end getErrorList()
3142

0 commit comments

Comments
 (0)