1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-12-21 21:30:08 +00:00

Use assert to verify invariants

This commit is contained in:
Tim Düsterhus 2022-03-04 18:28:07 +01:00
parent 00167fc6ed
commit be3b2657bf
Signed by: TimWolla
GPG Key ID: 8FF75566094168AF
4 changed files with 4 additions and 12 deletions

View File

@ -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;

View File

@ -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();

View File

@ -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,

View File

@ -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,