Skip to content

Commit 59b7919

Browse files
committed
PHPCSUtils 1.1.0: only catch what should be caught
PHPCSUtils 1.1.0 introduces much more modular exceptions for a variety of errors the utility methods can throw. This commit changes the exceptions being caught in various `catch` statements to more specific ones. This means that exceptions which shouldn't be able to occur are no longer caught (passing incorrect data type and such) and only the potentially expected (and acceptable) exceptions will now be caught.
1 parent 86b43ec commit 59b7919

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

WordPress/Helpers/ListHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
namespace WordPressCS\WordPress\Helpers;
1111

12-
use PHP_CodeSniffer\Exceptions\RuntimeException;
1312
use PHP_CodeSniffer\Files\File;
13+
use PHPCSUtils\Exceptions\UnexpectedTokenType;
1414
use PHPCSUtils\Tokens\Collections;
1515
use PHPCSUtils\Utils\Lists;
1616

@@ -67,7 +67,7 @@ public static function get_list_variables( File $phpcsFile, $stackPtr ) {
6767

6868
try {
6969
$assignments = Lists::getAssignments( $phpcsFile, $stackPtr );
70-
} catch ( RuntimeException $e ) {
70+
} catch ( UnexpectedTokenType $e ) {
7171
// Parse error/live coding.
7272
return array();
7373
}

WordPress/Sniffs/WP/EnqueuedResourcesSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
namespace WordPressCS\WordPress\Sniffs\WP;
1111

12-
use PHP_CodeSniffer\Exceptions\RuntimeException;
1312
use PHP_CodeSniffer\Util\Tokens;
13+
use PHPCSUtils\Exceptions\ValueError;
1414
use PHPCSUtils\Tokens\Collections;
1515
use PHPCSUtils\Utils\TextStrings;
1616
use WordPressCS\WordPress\Sniff;
@@ -54,7 +54,7 @@ public function process_token( $stackPtr ) {
5454
try {
5555
$end_ptr = TextStrings::getEndOfCompleteTextString( $this->phpcsFile, $stackPtr );
5656
$content = TextStrings::getCompleteTextString( $this->phpcsFile, $stackPtr );
57-
} catch ( RuntimeException $e ) {
57+
} catch ( ValueError $e ) {
5858
// Parse error/live coding.
5959
return;
6060
}

0 commit comments

Comments
 (0)