Use LogicException instead of Exception

Change-Id: I7fcf5e33d1db4d137b0275b0a11f4d69db619515
This commit is contained in:
Umherirrender 2024-02-21 22:46:45 +01:00
parent c54cea398a
commit 7fdd24ac9b
3 changed files with 7 additions and 13 deletions

View file

@ -2,9 +2,6 @@
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
// To migrate later
$cfg['suppress_issue_types'][] = 'MediaWikiNoBaseException';
$cfg['directory_list'] = array_merge(
$cfg['directory_list'],
[

View file

@ -2,8 +2,8 @@
namespace LoginNotify;
use Exception;
use Job;
use LogicException;
use MediaWiki\Title\Title;
use MediaWiki\User\UserFactory;
@ -38,17 +38,17 @@ class DeferredChecksJob extends Job {
// user_id exists in the database, we need to explicitly load.
$user->load();
if ( !$user->getId() ) {
throw new Exception( "Can't find user for user id=" . print_r( $userId, true ) );
throw new LogicException( "Can't find user for user id=" . print_r( $userId, true ) );
}
if ( !isset( $this->params['subnet'] ) || !is_string( $this->params['subnet'] ) ) {
throw new Exception( __CLASS__
throw new LogicException( __CLASS__
. " expected to receive a string parameter 'subnet', got "
. print_r( $this->params['subnet'], true )
);
}
$subnet = $this->params['subnet'];
if ( !isset( $this->params['resultSoFar'] ) || !is_string( $this->params['resultSoFar'] ) ) {
throw new Exception( __CLASS__
throw new LogicException( __CLASS__
. " expected to receive a string parameter 'resultSoFar', got "
. print_r( $this->params['resultSoFar'], true )
);
@ -65,7 +65,7 @@ class DeferredChecksJob extends Job {
$loginNotify->sendSuccessNoticeDeferred( $user, $subnet, $resultSoFar );
break;
default:
throw new Exception( 'Unknown check type ' . print_r( $checkType, true ) );
throw new LogicException( 'Unknown check type ' . print_r( $checkType, true ) );
}
return true;

View file

@ -9,11 +9,11 @@
namespace LoginNotify;
use BagOStuff;
use Exception;
use ExtensionRegistry;
use IBufferingStatsdDataFactory;
use JobQueueGroup;
use JobSpecification;
use LogicException;
use MediaWiki\Auth\AuthManager;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
@ -156,8 +156,6 @@ class LoginNotify implements LoggerAwareInterface {
*
* @param string $ip Either IPv4 or IPv6 address
* @return string Just the network part (e.g. 127.0.0.)
* @throws UnexpectedValueException If given something not an IP
* @throws Exception If regex totally fails (Should never happen)
*/
private function getIPNetwork( $ip ) {
$ip = IPUtils::sanitizeIP( $ip );
@ -172,7 +170,7 @@ class LoginNotify implements LoggerAwareInterface {
}
$prefix = preg_replace( $subnetRegex, '', $ip );
if ( !is_string( $prefix ) ) {
throw new Exception( __METHOD__ . " Regex failed on '$ip'!?" );
throw new LogicException( __METHOD__ . " Regex failed on '$ip'!?" );
}
return $prefix;
}
@ -367,7 +365,6 @@ class LoginNotify implements LoggerAwareInterface {
* @param WebRequest $request
* @param int $centralUserId
* @return int|string
* @throws Exception
*/
private function getSeenHash( WebRequest $request, int $centralUserId ) {
$ipPrefix = $this->getIPNetwork( $request->getIP() );