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

Start using the new exceptions #599

Merged
merged 2 commits into from
May 20, 2024
Merged

Commits on May 20, 2024

  1. Start using the new exceptions throughout PHPCSUtils

    This implements the use of the new exceptions introduced in 598 in all the right places in PHPCSUtils.
    
    Notes:
    * The `BCFile` class is explicitly exempt from this change as the methods in that class emulate the PHPCS native methods, which means they should also throw the PHPCS native exception.
    * Includes switching a number of test class from the `UtilityMethodTestCase` parent class to the `PolyfilledTestCase` parent class - which is basically the `UtilityMethodTestCase` + the PHPUnit Polyfills -. This allows for expecting the exceptions without having to jump through hoops for PHPUnit cross-version support.
    * Includes adding select extra tests where needed.
    jrfnl committed May 20, 2024
    Configuration menu
    Copy the full SHA
    9850475 View commit details
    Browse the repository at this point in the history
  2. Only catch what should be caught

    This changes the exceptions being caught in various `catch` statements to more specific ones.
    
    This means that errors which should always have been thrown, will now throw and only the potentially expected (and acceptable) exceptions will now be caught.
    
    Note:
    * For the `Namespaces::getDeclaredName()` method, the `catch` has not been changed (other than switching from the PHPCS native `RuntimeException` to the PHPCSUtils one).
        The reason for this is that the method is explicitly documented as returning `false` for non-existent tokens.
        While this behaviour is not in line with other methods in PHPCSUtils, changing the behaviour could be seen as a breaking change, so should be done in a major release.
    
    Includes test for where the behaviour of the functions is now different.
    jrfnl committed May 20, 2024
    Configuration menu
    Copy the full SHA
    1c9176d View commit details
    Browse the repository at this point in the history