Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(notifications): Add a dedicated exception when invalid values are…
… set

Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Apr 12, 2024
commit 834bd13e282516649134269787d98e6d53e9b2d9
2 changes: 2 additions & 0 deletions lib/composer/composer/LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

Copyright (c) Nils Adermann, Jordi Boggiano

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -17,3 +18,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@
'OCP\\Notification\\IManager' => $baseDir . '/lib/public/Notification/IManager.php',
'OCP\\Notification\\INotification' => $baseDir . '/lib/public/Notification/INotification.php',
'OCP\\Notification\\INotifier' => $baseDir . '/lib/public/Notification/INotifier.php',
'OCP\\Notification\\InvalidValueException' => $baseDir . '/lib/public/Notification/InvalidValueException.php',
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => $baseDir . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
'OCP\\OCM\\Exceptions\\OCMArgumentException' => $baseDir . '/lib/public/OCM/Exceptions/OCMArgumentException.php',
'OCP\\OCM\\Exceptions\\OCMProviderException' => $baseDir . '/lib/public/OCM/Exceptions/OCMProviderException.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Notification\\IManager' => __DIR__ . '/../../..' . '/lib/public/Notification/IManager.php',
'OCP\\Notification\\INotification' => __DIR__ . '/../../..' . '/lib/public/Notification/INotification.php',
'OCP\\Notification\\INotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/INotifier.php',
'OCP\\Notification\\InvalidValueException' => __DIR__ . '/../../..' . '/lib/public/Notification/InvalidValueException.php',
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => __DIR__ . '/../../..' . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
'OCP\\OCM\\Exceptions\\OCMArgumentException' => __DIR__ . '/../../..' . '/lib/public/OCM/Exceptions/OCMArgumentException.php',
'OCP\\OCM\\Exceptions\\OCMProviderException' => __DIR__ . '/../../..' . '/lib/public/OCM/Exceptions/OCMProviderException.php',
Expand Down
72 changes: 21 additions & 51 deletions lib/private/Notification/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,100 +25,72 @@
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;
return $this;
}

/**
* @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,
Expand All @@ -127,38 +99,36 @@ public function setLink(string $link, string $requestType): 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;
return $this;
}

/**
* @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 !== '';
Expand Down
Loading