Commit 53306fa
committed
Runner::processFile()/error handling: add more defensive coding
Follow up to squizlabs/PHP_CodeSniffer 3716 and PR 524.
PR squizlabs/PHP_CodeSniffer 3716 improved the information provided in the error messages for `Internal.Exception`s with additional information about the source of the problem.
This code uses the `Common::getSniffCode()` method to transform a sniff class name into a sniff code.
PR 524 changes how the `Common::getSniffCode()` method handles invalid input, i.e. it will now throw an exception when a class is passed which isn't a sniff (or sniff test).
In the context of this error handling, however, this new exception can easily be encountered when an `Abstract...Sniff` class contains the code which triggered the error - which would trigger the exception as it is not a sniff class.
This commit now adds some additional defensive coding to ensure that a) the error message will still be informative, while b) making sure that any exception which may be thrown by the `Common::getSniffCode()` method will be caught and and won't cause an uncaught `InvalidArgumentException` in the error handling code to stop execution of the script.
Includes a test documenting the behaviour of the `Common::getSniffCode()` method for abstract sniff classes.1 parent 36d731e commit 53306fa
2 files changed
+16
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
688 | 689 | | |
689 | 690 | | |
690 | 691 | | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
697 | 705 | | |
698 | 706 | | |
699 | 707 | | |
700 | | - | |
| 708 | + | |
701 | 709 | | |
702 | 710 | | |
703 | 711 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
| 111 | + | |
111 | 112 | | |
112 | 113 | | |
113 | 114 | | |
| |||
0 commit comments