Skip to content

Commit

Permalink
fix(psalm): Work around a psalm bug introduced with 5.18.0
Browse files Browse the repository at this point in the history
Ref vimeo/psalm#10534

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jan 9, 2024
1 parent bf40e31 commit 0e220a3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/Service/RoomService.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,31 +467,32 @@ public function setCallRecording(Room $room, int $status = Room::RECORDING_NONE,
/**
* @param Room $room
* @param int $newType Currently it is only allowed to change between `Room::TYPE_GROUP` and `Room::TYPE_PUBLIC`
* @param bool $allowSwitchingOneToOne
* @param bool $allowSwitchingOneToOne Allows additionally to change the type from `Room::TYPE_ONE_TO_ONE` to `Room::TYPE_ONE_TO_ONE_FORMER`
* @return bool True when the change was valid, false otherwise
*/
public function setType(Room $room, int $newType, bool $allowSwitchingOneToOne = false): bool {
if ($newType === $room->getType()) {
$oldType = $room->getType();
if ($oldType === $newType) {
return true;
}

if (!$allowSwitchingOneToOne && $room->getType() === Room::TYPE_ONE_TO_ONE) {
if (!$allowSwitchingOneToOne && $oldType === Room::TYPE_ONE_TO_ONE) {
return false;
}

if ($room->getType() === Room::TYPE_ONE_TO_ONE_FORMER) {
if ($oldType === Room::TYPE_ONE_TO_ONE_FORMER) {
return false;
}

if ($room->getType() === Room::TYPE_NOTE_TO_SELF) {
if ($oldType === Room::TYPE_NOTE_TO_SELF) {
return false;
}

if (!in_array($newType, [Room::TYPE_GROUP, Room::TYPE_PUBLIC, Room::TYPE_ONE_TO_ONE_FORMER], true)) {
return false;
}

if ($newType === Room::TYPE_ONE_TO_ONE_FORMER && $room->getType() !== Room::TYPE_ONE_TO_ONE) {
if ($newType === Room::TYPE_ONE_TO_ONE_FORMER && $oldType !== Room::TYPE_ONE_TO_ONE) {
return false;
}

Expand All @@ -503,8 +504,6 @@ public function setType(Room $room, int $newType, bool $allowSwitchingOneToOne =
return false;
}

$oldType = $room->getType();

$event = new BeforeRoomModifiedEvent($room, ARoomModifiedEvent::PROPERTY_TYPE, $newType, $oldType);
$this->dispatcher->dispatchTyped($event);

Expand Down

0 comments on commit 0e220a3

Please sign in to comment.