Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runner::processFile()/error handling: add more defensive coding #625

Merged
merged 1 commit into from
Oct 7, 2024

Commits on Oct 3, 2024

  1. Runner::processFile()/error handling: add more defensive coding

    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 the `Common::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 uncaught `InvalidArgumentException` 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.
    jrfnl committed Oct 3, 2024
    Configuration menu
    Copy the full SHA
    53306fa View commit details
    Browse the repository at this point in the history