From 7fdd24ac9b060f78144037c0ad6c22730e5d3371 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Wed, 21 Feb 2024 22:46:45 +0100 Subject: [PATCH] Use LogicException instead of Exception Change-Id: I7fcf5e33d1db4d137b0275b0a11f4d69db619515 --- .phan/config.php | 3 --- includes/DeferredChecksJob.php | 10 +++++----- includes/LoginNotify.php | 7 ++----- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 4dea717..c19cdc5 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -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'], [ diff --git a/includes/DeferredChecksJob.php b/includes/DeferredChecksJob.php index 2f6bfab..a178e37 100644 --- a/includes/DeferredChecksJob.php +++ b/includes/DeferredChecksJob.php @@ -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; diff --git a/includes/LoginNotify.php b/includes/LoginNotify.php index bddcaf3..36d1e7f 100644 --- a/includes/LoginNotify.php +++ b/includes/LoginNotify.php @@ -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() );