Closed jrfnl closed 3 months ago
Rebased without changes, other than squashing the "catch change/test" commit into the commit making the catch changes. Marking as ready as https://github.com/PHPCSStandards/PHPCSUtils/pull/598 has been merged now. Merging once the build passes.
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:
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.UtilityMethodTestCase
parent class to thePolyfilledTestCase
parent class - which is basically theUtilityMethodTestCase
+ the PHPUnit Polyfills -. This allows for expecting the exceptions without having to jump through hoops for PHPUnit cross-version support.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:
Namespaces::getDeclaredName()
method, thecatch
has not been changed (other than switching from the PHPCS nativeRuntimeException
to the PHPCSUtils one). The reason for this is that the method is explicitly documented as returningfalse
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.