aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Notification/Action.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2024-04-10 15:50:17 +0200
committerJoas Schilling <coding@schilljs.com>2024-04-12 09:23:15 +0200
commit834bd13e282516649134269787d98e6d53e9b2d9 (patch)
tree7e20d07b402d4b8a6e2a690052a7ab0a0d7b69c1 /lib/private/Notification/Action.php
parent715077ea70f0ed18d1f742a4ef3486e4bfa1b111 (diff)
downloadnextcloud-server-834bd13e282516649134269787d98e6d53e9b2d9.tar.gz
nextcloud-server-834bd13e282516649134269787d98e6d53e9b2d9.zip
fix(notifications): Add a dedicated exception when invalid values are set
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Notification/Action.php')
-rw-r--r--lib/private/Notification/Action.php72
1 files changed, 21 insertions, 51 deletions
diff --git a/lib/private/Notification/Action.php b/lib/private/Notification/Action.php
index 9590d28af4a..8307960cf06 100644
--- a/lib/private/Notification/Action.php
+++ b/lib/private/Notification/Action.php
@@ -25,76 +25,53 @@ declare(strict_types=1);
namespace OC\Notification;
use OCP\Notification\IAction;
+use OCP\Notification\InvalidValueException;
class Action implements IAction {
- protected string $label;
-
- protected string $labelParsed;
-
- protected string $link;
-
- protected string $requestType;
-
- protected string $icon;
-
- protected bool $primary;
-
- public function __construct() {
- $this->label = '';
- $this->labelParsed = '';
- $this->link = '';
- $this->requestType = '';
- $this->primary = false;
- }
+ protected string $label = '';
+ protected string $labelParsed = '';
+ protected string $link = '';
+ protected string $requestType = '';
+ protected bool $primary = false;
/**
- * @param string $label
- * @return $this
- * @throws \InvalidArgumentException if the label is invalid
- * @since 8.2.0
+ * {@inheritDoc}
*/
public function setLabel(string $label): IAction {
if ($label === '' || isset($label[32])) {
- throw new \InvalidArgumentException('The given label is invalid');
+ throw new InvalidValueException('label');
}
$this->label = $label;
return $this;
}
/**
- * @return string
- * @since 8.2.0
+ * {@inheritDoc}
*/
public function getLabel(): string {
return $this->label;
}
/**
- * @param string $label
- * @return $this
- * @throws \InvalidArgumentException if the label is invalid
- * @since 8.2.0
+ * {@inheritDoc}
*/
public function setParsedLabel(string $label): IAction {
if ($label === '') {
- throw new \InvalidArgumentException('The given parsed label is invalid');
+ throw new InvalidValueException('parsedLabel');
}
$this->labelParsed = $label;
return $this;
}
/**
- * @return string
- * @since 8.2.0
+ * {@inheritDoc}
*/
public function getParsedLabel(): string {
return $this->labelParsed;
}
/**
- * @param $primary bool
- * @return $this
- * @since 9.0.0
+ * {@inheritDoc}
*/
public function setPrimary(bool $primary): IAction {
$this->primary = $primary;
@@ -102,23 +79,18 @@ class Action implements IAction {
}
/**
- * @return bool
- * @since 9.0.0
+ * {@inheritDoc}
*/
public function isPrimary(): bool {
return $this->primary;
}
/**
- * @param string $link
- * @param string $requestType
- * @return $this
- * @throws \InvalidArgumentException if the link is invalid
- * @since 8.2.0
+ * {@inheritDoc}
*/
public function setLink(string $link, string $requestType): IAction {
if ($link === '' || isset($link[256])) {
- throw new \InvalidArgumentException('The given link is invalid');
+ throw new InvalidValueException('link');
}
if (!in_array($requestType, [
self::TYPE_GET,
@@ -127,7 +99,7 @@ class Action implements IAction {
self::TYPE_DELETE,
self::TYPE_WEB,
], true)) {
- throw new \InvalidArgumentException('The given request type is invalid');
+ throw new InvalidValueException('requestType');
}
$this->link = $link;
$this->requestType = $requestType;
@@ -135,30 +107,28 @@ class Action implements IAction {
}
/**
- * @return string
- * @since 8.2.0
+ * {@inheritDoc}
*/
public function getLink(): string {
return $this->link;
}
/**
- * @return string
- * @since 8.2.0
+ * {@inheritDoc}
*/
public function getRequestType(): string {
return $this->requestType;
}
/**
- * @return bool
+ * {@inheritDoc}
*/
public function isValid(): bool {
return $this->label !== '' && $this->link !== '';
}
/**
- * @return bool
+ * {@inheritDoc}
*/
public function isValidParsed(): bool {
return $this->labelParsed !== '' && $this->link !== '';