Skip to content

Commit 1a39d36

Browse files
committed
Universal/DisallowUse*: 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. Refs: * PHPCSStandards/PHPCSUtils 598 * PHPCSStandards/PHPCSUtils 599 * PHPCSStandards/PHPCSUtils 600
1 parent df7233e commit 1a39d36

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

Universal/Sniffs/UseStatements/DisallowUseClassSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace PHPCSExtra\Universal\Sniffs\UseStatements;
1212

13-
use PHP_CodeSniffer\Exceptions\RuntimeException;
1413
use PHP_CodeSniffer\Files\File;
1514
use PHP_CodeSniffer\Sniffs\Sniff;
1615
use PHP_CodeSniffer\Util\Tokens;
16+
use PHPCSUtils\Exceptions\ValueError;
1717
use PHPCSUtils\Utils\Namespaces;
1818
use PHPCSUtils\Utils\UseStatements;
1919

@@ -115,7 +115,7 @@ public function process(File $phpcsFile, $stackPtr)
115115
// Ok, so this is a T_USE token.
116116
try {
117117
$statements = UseStatements::splitImportUseStatement($phpcsFile, $stackPtr);
118-
} catch (RuntimeException $e) {
118+
} catch (ValueError $e) {
119119
// Not an import use statement. Bow out.
120120
return;
121121
}

Universal/Sniffs/UseStatements/DisallowUseConstSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace PHPCSExtra\Universal\Sniffs\UseStatements;
1212

13-
use PHP_CodeSniffer\Exceptions\RuntimeException;
1413
use PHP_CodeSniffer\Files\File;
1514
use PHP_CodeSniffer\Sniffs\Sniff;
1615
use PHP_CodeSniffer\Util\Tokens;
16+
use PHPCSUtils\Exceptions\ValueError;
1717
use PHPCSUtils\Utils\Namespaces;
1818
use PHPCSUtils\Utils\UseStatements;
1919

@@ -115,7 +115,7 @@ public function process(File $phpcsFile, $stackPtr)
115115
// Ok, so this is a T_USE token.
116116
try {
117117
$statements = UseStatements::splitImportUseStatement($phpcsFile, $stackPtr);
118-
} catch (RuntimeException $e) {
118+
} catch (ValueError $e) {
119119
// Not an import use statement. Bow out.
120120
return;
121121
}

Universal/Sniffs/UseStatements/DisallowUseFunctionSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
namespace PHPCSExtra\Universal\Sniffs\UseStatements;
1212

13-
use PHP_CodeSniffer\Exceptions\RuntimeException;
1413
use PHP_CodeSniffer\Files\File;
1514
use PHP_CodeSniffer\Sniffs\Sniff;
1615
use PHP_CodeSniffer\Util\Tokens;
16+
use PHPCSUtils\Exceptions\ValueError;
1717
use PHPCSUtils\Utils\Namespaces;
1818
use PHPCSUtils\Utils\UseStatements;
1919

@@ -115,7 +115,7 @@ public function process(File $phpcsFile, $stackPtr)
115115
// Ok, so this is a T_USE token.
116116
try {
117117
$statements = UseStatements::splitImportUseStatement($phpcsFile, $stackPtr);
118-
} catch (RuntimeException $e) {
118+
} catch (ValueError $e) {
119119
// Not an import use statement. Bow out.
120120
return;
121121
}

0 commit comments

Comments
 (0)