From be3b2657bf2c81d1d4601336fc6dbcddb3872268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Fri, 4 Mar 2022 18:28:07 +0100 Subject: [PATCH] Use assert to verify invariants --- files/lib/data/room/RoomAction.class.php | 4 +--- .../system/attachment/MessageAttachmentObjectType.class.php | 4 +--- .../system/event/listener/RoomCanJoinBanListener.class.php | 4 +--- .../event/listener/RoomCanWritePubliclyMuteListener.class.php | 4 +--- 4 files changed, 4 insertions(+), 12 deletions(-) diff --git a/files/lib/data/room/RoomAction.class.php b/files/lib/data/room/RoomAction.class.php index c4d11f6..5686950 100644 --- a/files/lib/data/room/RoomAction.class.php +++ b/files/lib/data/room/RoomAction.class.php @@ -291,9 +291,7 @@ public function leave() AND userID = ?"; $statement = WCF::getDB()->prepare($sql); $statement->execute([ 0, $room->roomID, $user->userID ]); - if ($statement->getAffectedRows() === 0) { - throw new \LogicException('Unreachable'); - } + \assert($statement->getAffectedRows() > 0); WCF::getDB()->commitTransaction(); $commited = true; diff --git a/files/lib/system/attachment/MessageAttachmentObjectType.class.php b/files/lib/system/attachment/MessageAttachmentObjectType.class.php index 99212d4..dcc2ec8 100644 --- a/files/lib/system/attachment/MessageAttachmentObjectType.class.php +++ b/files/lib/system/attachment/MessageAttachmentObjectType.class.php @@ -35,9 +35,7 @@ public function canDownload($objectID) if ($objectID) { $message = new Message($objectID); - if ($message->getMessageType()->objectType !== 'be.bastelstu.chat.messageType.attachment') { - throw new \LogicException('Unreachable'); - } + \assert($message->getMessageType()->objectType === 'be.bastelstu.chat.messageType.attachment'); $room = $message->getRoom(); return $room->canSee(); diff --git a/files/lib/system/event/listener/RoomCanJoinBanListener.class.php b/files/lib/system/event/listener/RoomCanJoinBanListener.class.php index 10de3aa..0ea920d 100644 --- a/files/lib/system/event/listener/RoomCanJoinBanListener.class.php +++ b/files/lib/system/event/listener/RoomCanJoinBanListener.class.php @@ -35,9 +35,7 @@ public function execute($eventObj, $className, $eventName, array &$parameters) 'be.bastelstu.chat.suspension', 'be.bastelstu.chat.suspension.ban' ); - if (!$objectTypeID) { - throw new \LogicException('Unreachable'); - } + \assert($objectTypeID !== null); $suspensions = Suspension::getActiveSuspensionsByTriple( $objectTypeID, diff --git a/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php b/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php index 1d2f491..104ea2a 100644 --- a/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php +++ b/files/lib/system/event/listener/RoomCanWritePubliclyMuteListener.class.php @@ -35,9 +35,7 @@ public function execute($eventObj, $className, $eventName, array &$parameters) 'be.bastelstu.chat.suspension', 'be.bastelstu.chat.suspension.mute' ); - if (!$objectTypeID) { - throw new \LogicException('Unreachable'); - } + \assert($objectTypeID !== null); $suspensions = Suspension::getActiveSuspensionsByTriple( $objectTypeID,