Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 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.