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

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented May 13, 2024

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 classes 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.

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 jrfnl added this to the 1.1.0 milestone May 13, 2024
@jrfnl jrfnl changed the title Feature/start using the new exceptions Start using the new exceptions May 13, 2024
@jrfnl jrfnl force-pushed the feature/start-using-the-new-exceptions branch 2 times, most recently from 10aa322 to 5680552 Compare May 14, 2024 06:53
@jrfnl jrfnl force-pushed the feature/introduce-better-exceptions branch from d06975f to 8b08c1e Compare May 20, 2024 18:18
Base automatically changed from feature/introduce-better-exceptions to develop May 20, 2024 18:24
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 jrfnl force-pushed the feature/start-using-the-new-exceptions branch from 5680552 to 18fb796 Compare May 20, 2024 18:26
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
Copy link
Member Author

jrfnl commented May 20, 2024

Rebased without changes, other than squashing the "catch change/test" commit into the commit making the catch changes.
Marking as ready as #598 has been merged now. Merging once the build passes.

@jrfnl jrfnl marked this pull request as ready for review May 20, 2024 18:28
@jrfnl jrfnl force-pushed the feature/start-using-the-new-exceptions branch from 18fb796 to 1c9176d Compare May 20, 2024 18:28
@jrfnl jrfnl merged commit a66c8d4 into develop May 20, 2024
54 checks passed
@jrfnl jrfnl deleted the feature/start-using-the-new-exceptions branch May 20, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant