Skip to content

2.0 | Rethink exception hierarchy #676

Open
@jrfnl

Description

@jrfnl

PHPCSUtils 1.1.0 introduced a number of new exceptions via #598 (and started using them via #599).

These exceptions currently all extend the PHPCSUtils PHPCSUtils\Exceptions\RuntimeException, which in turn extends the PHPCS native PHP_CodeSniffer\Exceptions\RuntimeException.

This was done in this way to allow for introducing these exceptions into pre-existing functionality, which already threw a RuntimeException, without this being a breaking change.

However, strictly speaking, a number of these exceptions should extend a different PHP native exception for improved semantics.

Case(s) in point:

  • The PHPCSUtils LogicException would be better off extending the PHP native LogicException.
  • The PHPCSUtils MissingArgumentError would be better off extending the PHP native ArgumentCountError.
  • The PHPCSUtils OutOfBoundsStackPtr would be better off extending the PHP native OutOfBoundsException.
  • The PHPCSUtils TypeError would be better off extending the PHP native TypeError.
  • The PHPCSUtils UnexpectedTokenType would be better off extending the PHP native InvalidArgumentException.
  • The PHPCSUtils ValueError would be better off extending the PHP native InvalidArgumentException or the PHP 8.0+ native ValueError.

Having said that, making these changes would be a breaking change and the current exceptions are already much more descriptive than the original RuntimeException, so addressing this is not urgent and may not be needed at all.

Opening this issue to solicit opinions and as a reminder to think this over again before the next major release.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions