Skip to content

Commit 57ae79b

Browse files
committed
Merge branch 'feature/2565-generic-inlinecontrolstructure-bugfix' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 78124a0 + 9716919 commit 57ae79b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
505505
<file baseinstalldir="PHP/CodeSniffer" name="InlineControlStructureUnitTest.4.inc" role="test" />
506506
<file baseinstalldir="PHP/CodeSniffer" name="InlineControlStructureUnitTest.5.inc" role="test" />
507507
<file baseinstalldir="PHP/CodeSniffer" name="InlineControlStructureUnitTest.6.inc" role="test" />
508+
<file baseinstalldir="PHP/CodeSniffer" name="InlineControlStructureUnitTest.7.inc" role="test" />
508509
<file baseinstalldir="PHP/CodeSniffer" name="InlineControlStructureUnitTest.js" role="test" />
509510
<file baseinstalldir="PHP/CodeSniffer" name="InlineControlStructureUnitTest.js.fixed" role="test" />
510511
<file baseinstalldir="PHP/CodeSniffer" name="InlineControlStructureUnitTest.php" role="test" />

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,16 @@ public function process(File $phpcsFile, $stackPtr)
140140
return;
141141
}
142142

143+
if ($tokens[$nextNonEmpty]['code'] === T_COLON) {
144+
var_dump($tokens[$nextNonEmpty]);
145+
// Alternative control structure.
146+
// T_END... missing. Either live coding, parse error or end
147+
// tag in short open tags and scan run with short_open_tag=Off.
148+
// Bow out completely as any further detection will be unreliable
149+
// and create incorrect fixes or cause fixer conflicts.
150+
return ($phpcsFile->numTokens + 1);
151+
}
152+
143153
unset($nextNonEmpty, $start);
144154

145155
// This is a control structure without an opening brace,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
// Issue #2565.
3+
// Important note: this file intentionally does not have a ".fixed" version as
4+
// when `short_open_tag=Off`, no fixes will be made, while when `short_open_tag=On`
5+
// no fixes are necessary.
6+
?>
7+
8+
<?php if (true) : ?>
9+
<? endif ?>
10+
<?php if (true) { ?>
11+
<? } ?>
12+
13+
<? if (false) : ?>
14+
<? endif ?>
15+
<?php if (false) { ?>
16+
<?php } ?>

0 commit comments

Comments
 (0)