-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EarlyExit: don't break the complete PHPCS run for unsupported syntaxes
While it is your prerogative, of course, to choose not to support certain syntaxes, when these are encountered the sniff should exit silently. As things were, the sniff would exit with an _uncaught exception_ which within PHPCS was then translated to an `Internal.Exception` error which stops the PHPCS dead for the file being scanned, this includes breaking the run for all other sniffs in a project ruleset. Exceptions are intended for developers, not for end-users. The end-user of PHPCS can do nothing with an uncaught exception. Instead, this exception should be caught within the sniff and he sniff should return silently as it couldn't be determined whether something is or isn't an error for the rules the sniff is checking for. Includes adjusted unit tests + a new unit test for control structures using alternative syntax, which clearly isn't supported either and would - until now - cause an `Undefined index: scope_condition` notice, which - again - would stop the PHPCS scan dead.
- Loading branch information
Showing
3 changed files
with
56 additions
and
20 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
12 changes: 12 additions & 0 deletions
12
tests/Sniffs/ControlStructures/data/earlyExitAlternativeSyntax.php
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,12 @@ | ||
<?php | ||
|
||
function () { | ||
if (true) : ?> | ||
<div></div> | ||
<?php elseif (false) : ?> | ||
<div></div> | ||
<?php else : ?> | ||
<div></div> | ||
<?php | ||
endif; | ||
}; |