fix(activity): Add a dedicated exception when the filter or setting is not found

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2024-04-17 15:29:33 +02:00
parent 784ab6e79a
commit 9f4845e25b
No known key found for this signature in database
GPG Key ID: 74434EFE0D2E2205
6 changed files with 112 additions and 12 deletions

View File

@ -14,8 +14,10 @@ return array(
'OCP\\Accounts\\PropertyDoesNotExistException' => $baseDir . '/lib/public/Accounts/PropertyDoesNotExistException.php',
'OCP\\Accounts\\UserUpdatedEvent' => $baseDir . '/lib/public/Accounts/UserUpdatedEvent.php',
'OCP\\Activity\\ActivitySettings' => $baseDir . '/lib/public/Activity/ActivitySettings.php',
'OCP\\Activity\\Exceptions\\FilterNotFoundException' => $baseDir . '/lib/public/Activity/Exceptions/FilterNotFoundException.php',
'OCP\\Activity\\Exceptions\\IncompleteActivityException' => $baseDir . '/lib/public/Activity/Exceptions/IncompleteActivityException.php',
'OCP\\Activity\\Exceptions\\InvalidValueException' => $baseDir . '/lib/public/Activity/Exceptions/InvalidValueException.php',
'OCP\\Activity\\Exceptions\\SettingNotFoundException' => $baseDir . '/lib/public/Activity/Exceptions/SettingNotFoundException.php',
'OCP\\Activity\\Exceptions\\UnknownActivityException' => $baseDir . '/lib/public/Activity/Exceptions/UnknownActivityException.php',
'OCP\\Activity\\IConsumer' => $baseDir . '/lib/public/Activity/IConsumer.php',
'OCP\\Activity\\IEvent' => $baseDir . '/lib/public/Activity/IEvent.php',

View File

@ -47,8 +47,10 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Accounts\\PropertyDoesNotExistException' => __DIR__ . '/../../..' . '/lib/public/Accounts/PropertyDoesNotExistException.php',
'OCP\\Accounts\\UserUpdatedEvent' => __DIR__ . '/../../..' . '/lib/public/Accounts/UserUpdatedEvent.php',
'OCP\\Activity\\ActivitySettings' => __DIR__ . '/../../..' . '/lib/public/Activity/ActivitySettings.php',
'OCP\\Activity\\Exceptions\\FilterNotFoundException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/FilterNotFoundException.php',
'OCP\\Activity\\Exceptions\\IncompleteActivityException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/IncompleteActivityException.php',
'OCP\\Activity\\Exceptions\\InvalidValueException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/InvalidValueException.php',
'OCP\\Activity\\Exceptions\\SettingNotFoundException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/SettingNotFoundException.php',
'OCP\\Activity\\Exceptions\\UnknownActivityException' => __DIR__ . '/../../..' . '/lib/public/Activity/Exceptions/UnknownActivityException.php',
'OCP\\Activity\\IConsumer' => __DIR__ . '/../../..' . '/lib/public/Activity/IConsumer.php',
'OCP\\Activity\\IEvent' => __DIR__ . '/../../..' . '/lib/public/Activity/IEvent.php',

View File

@ -29,7 +29,9 @@
namespace OC\Activity;
use OCP\Activity\ActivitySettings;
use OCP\Activity\Exceptions\FilterNotFoundException;
use OCP\Activity\Exceptions\IncompleteActivityException;
use OCP\Activity\Exceptions\SettingNotFoundException;
use OCP\Activity\IConsumer;
use OCP\Activity\IEvent;
use OCP\Activity\IFilter;
@ -198,10 +200,7 @@ class Manager implements IManager {
}
/**
* @param string $id
* @return IFilter
* @throws \InvalidArgumentException when the filter was not found
* @since 11.0.0
* {@inheritDoc}
*/
public function getFilterById(string $id): IFilter {
$filters = $this->getFilters();
@ -210,7 +209,7 @@ class Manager implements IManager {
return $filters[$id];
}
throw new \InvalidArgumentException('Requested filter does not exist');
throw new FilterNotFoundException($id);
}
/** @var string[] */
@ -286,10 +285,7 @@ class Manager implements IManager {
}
/**
* @param string $id
* @return ActivitySettings
* @throws \InvalidArgumentException when the setting was not found
* @since 11.0.0
* {@inheritDoc}
*/
public function getSettingById(string $id): ActivitySettings {
$settings = $this->getSettings();
@ -298,7 +294,7 @@ class Manager implements IManager {
return $settings[$id];
}
throw new \InvalidArgumentException('Requested setting does not exist');
throw new SettingNotFoundException($id);
}

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2024 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCP\Activity\Exceptions;
/**
* @since 30.0.0
*/
class FilterNotFoundException extends \InvalidArgumentException {
/**
* @since 30.0.0
*/
public function __construct(
protected string $filter,
) {
parent::__construct('Filter ' . $filter . ' not found');
}
/**
* @since 30.0.0
*/
public function getFilterId(): string {
return $this->filter;
}
}

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2024 Joas Schilling <coding@schilljs.com>
*
* @author Joas Schilling <coding@schilljs.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCP\Activity\Exceptions;
/**
* @since 30.0.0
*/
class SettingNotFoundException extends \InvalidArgumentException {
/**
* @since 30.0.0
*/
public function __construct(
protected string $setting,
) {
parent::__construct('Setting ' . $setting . ' not found');
}
/**
* @since 30.0.0
*/
public function getSettingId(): string {
return $this->setting;
}
}

View File

@ -28,7 +28,9 @@ declare(strict_types=1);
*/
namespace OCP\Activity;
use OCP\Activity\Exceptions\FilterNotFoundException;
use OCP\Activity\Exceptions\IncompleteActivityException;
use OCP\Activity\Exceptions\SettingNotFoundException;
/**
* Interface IManager
@ -95,8 +97,9 @@ interface IManager {
/**
* @param string $id
* @return IFilter
* @throws \InvalidArgumentException when the filter was not found
* @throws FilterNotFoundException when the filter was not found
* @since 11.0.0
* @since 30.0.0 throws {@see FilterNotFoundException} instead of \InvalidArgumentException
*/
public function getFilterById(string $id): IFilter;
@ -127,8 +130,9 @@ interface IManager {
/**
* @param string $id
* @return ActivitySettings
* @throws \InvalidArgumentException when the setting was not found
* @throws SettingNotFoundException when the setting was not found
* @since 11.0.0
* @since 30.0.0 throws {@see SettingNotFoundException} instead of \InvalidArgumentException
*/
public function getSettingById(string $id): ActivitySettings;