Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Oct 12, 2022

This introduces the first PHPCSUtils native exception, which will extend the PHPCS native PHP_CodeSniffer\Exceptions\RuntimeException, to throw an informative exception when a non-existent token array is requested.

Includes implementing use of the new Exception in the BCTokens::__callStatic() method.

Includes a unit test for the Exception.

Notes:

  • While this does constitute a change in behaviour for the BCTokens class, it should not be considered a breaking change as this handles a state which was invalid to begin with.
  • Also note, that while another "base Exception" to extend, may be semantically more correct, using the PHPCS native RuntimeException follows the principle of "least surprise" as that is normally the only exception sniffs will encounter and this new Exception can still be caught by referencing the PHPCS native RuntimeException class.

This introduces the first PHPCSUtils native exception, which will extend the PHPCS native `PHP_CodeSniffer\Exceptions\RuntimeException`, to throw an informative exception when a non-existent token array is requested.

Includes implementing use of the new Exception in the `BCTokens::__callStatic()` method.

Includes a unit test for the Exception.

Notes:
* While this does constitute a change in behaviour for the `BCTokens` class, it should not be considered a breaking change as this handles a state which was invalid to begin with.
* Also note, that while another "base Exception" to extend, may be semantically more correct, using the PHPCS native `RuntimeException` follows the principle of "least surprise" as that is normally the only exception sniffs will encounter and this new Exception can still be caught by referencing the PHPCS native `RuntimeException` class.
@jrfnl
Copy link
Member Author

jrfnl commented Oct 12, 2022

Coveralls is still drunk. Real code coverage is now 98.14 % with 100% of the code in this PR covered.

@jrfnl jrfnl merged commit 2519d98 into develop Oct 12, 2022
@jrfnl jrfnl deleted the feature/start-using-phpcsutils-native-exceptions branch October 12, 2022 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants