-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squiz/NonExecutableCode: fix false positives when code goes in and ou…
…t of PHP/HTML (#3770) Ignore HTML whitespace and PHP re-open tags when determining whether code should be flagged as non executable.
- Loading branch information
Showing
4 changed files
with
101 additions
and
3 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
64 changes: 64 additions & 0 deletions
64
src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.3.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,64 @@ | ||
<!-- no problem here --> | ||
<?php if (true): ?> | ||
<?php foreach ([] as $item): ?> | ||
<?php continue; ?> | ||
<?php endforeach; ?> | ||
<?php endif; ?> | ||
|
||
<!-- no problem here --> | ||
<?php if (true) { ?> | ||
<?php foreach ([] as $item) { ?> | ||
<?php continue; ?> | ||
<?php } ?> | ||
<?php } ?> | ||
|
||
<!-- no problem here --> | ||
<?php if (true) { ?> | ||
<?php foreach ([] as $item) { ?> | ||
<!-- note missing semicolon on next line --> | ||
<?php continue ?> | ||
<?php } ?> | ||
<?php } ?> | ||
|
||
<!-- should detect an error here --> | ||
<?php if (true): ?> | ||
<?php foreach ([] as $item): ?> | ||
<?php continue; ?> | ||
<div>non-executable</div> | ||
<?php endforeach; ?> | ||
<?php endif; ?> | ||
|
||
<!-- should detect an error here --> | ||
<?php if (true): ?> | ||
<?php foreach ([] as $item): ?> | ||
<!-- note missing semicolon on next line --> | ||
<?php continue ?> | ||
<div>non-executable</div> | ||
<?php endforeach; ?> | ||
<?php endif; ?> | ||
|
||
<!-- should detect an error here --> | ||
<?php if (true): ?> | ||
<?php foreach ([] as $item): ?> | ||
<?php continue; ?> | ||
|
||
<div>non-executable</div> | ||
|
||
<?php endforeach; ?> | ||
<?php endif; ?> | ||
|
||
<!-- should detect an error here --> | ||
<?php if (true): ?> | ||
<?php foreach ([] as $item): ?> | ||
<?php continue; ?> | ||
<?= 'unreachable - no semicolon' ?> | ||
<?php endforeach; ?> | ||
<?php endif; ?> | ||
|
||
<!-- should detect an error here --> | ||
<?php if (true): ?> | ||
<?php foreach ([] as $item): ?> | ||
<?php continue; ?> | ||
<?= 'unreachable - with semicolon'; ?> | ||
<?php endforeach; ?> | ||
<?php endif; ?> |
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