getUser(); if (!$user instanceof User) { return false; } if ($subject instanceof Notification) { return match ($attribute) { self::COMMENT_ADD => false === $subject->isSystem() && ( $subject->getAddressees()->contains($user) || $subject->getSender() === $user ), self::NOTIFICATION_SEE, self::NOTIFICATION_TOGGLE_READ_STATUS => $subject->getSender() === $user || $subject->getAddressees()->contains($user), self::NOTIFICATION_UPDATE => $subject->getSender() === $user && false === $subject->isSystem(), default => throw new \UnexpectedValueException("this subject {$attribute} is not implemented"), }; } elseif ($subject instanceof NotificationComment) { return match ($attribute) { self::COMMENT_ADD => false === $subject->getNotification()->isSystem() && ( $subject->getNotification()->getAddressees()->contains($user) || $subject->getNotification()->getSender() === $user ), self::COMMENT_EDIT => $subject->getCreatedBy() === $user && false === $subject->getNotification()->isSystem(), default => throw new \UnexpectedValueException("this subject {$attribute} is not implemented"), }; } throw new \UnexpectedValueException(); } }