diff options
-rw-r--r-- | lib/private/Activity/Event.php | 12 | ||||
-rw-r--r-- | lib/private/Notification/Notification.php | 12 |
2 files changed, 14 insertions, 10 deletions
diff --git a/lib/private/Activity/Event.php b/lib/private/Activity/Event.php index 806a7514590..cc1135cf179 100644 --- a/lib/private/Activity/Event.php +++ b/lib/private/Activity/Event.php @@ -276,19 +276,21 @@ class Event implements IEvent { } /** - * @throws \InvalidArgumentException if a parameter has no name + * @throws \InvalidArgumentException if a parameter has no name or no type */ private function richToParsed(string $message, array $parameters): string { $placeholders = []; $replacements = []; foreach ($parameters as $placeholder => $parameter) { $placeholders[] = '{' . $placeholder . '}'; - if (!isset($parameter['name']) || !is_string($parameter['name'])) { - throw new \InvalidArgumentException('Invalid rich object, name field is missing'); + foreach (['name','type'] as $requiredField) { + if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) { + throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing"); + } } - if (($parameter['type'] ?? '') === 'user') { + if ($parameter['type'] === 'user') { $replacements[] = '@' . $parameter['name']; - } elseif (($parameter['type'] ?? '') === 'file') { + } elseif ($parameter['type'] === 'file') { $replacements[] = $parameter['path'] ?? $parameter['name']; } else { $replacements[] = $parameter['name']; diff --git a/lib/private/Notification/Notification.php b/lib/private/Notification/Notification.php index 1ced034d7c6..2291c4ae34f 100644 --- a/lib/private/Notification/Notification.php +++ b/lib/private/Notification/Notification.php @@ -303,19 +303,21 @@ class Notification implements INotification { } /** - * @throws \InvalidArgumentException if a parameter has no name + * @throws \InvalidArgumentException if a parameter has no name or no type */ private function richToParsed(string $message, array $parameters): string { $placeholders = []; $replacements = []; foreach ($parameters as $placeholder => $parameter) { $placeholders[] = '{' . $placeholder . '}'; - if (!isset($parameter['name']) || !is_string($parameter['name'])) { - throw new \InvalidArgumentException('Invalid rich object, name field is missing'); + foreach (['name','type'] as $requiredField) { + if (!isset($parameter[$requiredField]) || !is_string($parameter[$requiredField])) { + throw new \InvalidArgumentException("Invalid rich object, {$requiredField} field is missing"); + } } - if (($parameter['type'] ?? '') === 'user') { + if ($parameter['type'] === 'user') { $replacements[] = '@' . $parameter['name']; - } elseif (($parameter['type'] ?? '') === 'file') { + } elseif ($parameter['type'] === 'file') { $replacements[] = $parameter['path'] ?? $parameter['name']; } else { $replacements[] = $parameter['name']; |