Runner::processFile()/error handling: add more defensive coding #625
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Follow up to squizlabs/PHP_CodeSniffer#3716 and PR #524.
PR squizlabs/PHP_CodeSniffer#3716 improved the information provided in the error messages for
Internal.Exception
s with additional information about the source of the problem. This code uses theCommon::getSniffCode()
method to transform a sniff class name into a sniff code.PR #524 changes how the
Common::getSniffCode()
method handles invalid input, i.e. it will now throw an exception when a class is passed which isn't a sniff (or sniff test).In the context of this error handling, however, this new exception can easily be encountered when an
Abstract...Sniff
class contains the code which triggered the error - which would trigger the exception as it is not a sniff class.This commit now adds some additional defensive coding to ensure that a) the error message will still be informative, while b) making sure that any exception which may be thrown by the
Common::getSniffCode()
method will be caught and and won't cause an uncaughtInvalidArgumentException
in the error handling code to stop execution of the script.Includes a test documenting the behaviour of the
Common::getSniffCode()
method for abstract sniff classes.Suggested changelog entry
should be covered via the changelog entry for #524