From 2e4eca1c75f50163471480689cd78dafa08e5964 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sat, 9 Mar 2024 12:48:40 +0100 Subject: [PATCH] chore(tests): UT for ItemPreset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../Account/ViewPassController.php | 8 +- .../Account/ViewPassHistoryController.php | 8 +- .../AccountFile/UploadController.php | 10 +- .../Helpers/Account/AccountHelper.php | 92 +++-- .../Helpers/Account/AccountPasswordHelper.php | 12 +- .../Controllers/Helpers/ItemPresetHelper.php | 4 +- .../ItemManager/IndexController.php | 12 +- .../ItemPreset/ItemPresetSaveBase.php | 10 +- .../ItemPreset/ItemPresetViewBase.php | 16 +- .../ItemPreset/SaveCreateController.php | 4 +- .../ItemPreset/SaveEditController.php | 4 +- .../ItemPreset/SearchController.php | 14 +- .../Items/NotificationsController.php | 6 +- .../Notification/NotificationViewBase.php | 6 +- .../UserProfile/UserProfileViewBase.php | 4 +- app/modules/web/Forms/ItemsPresetForm.php | 6 +- app/modules/web/Forms/NotificationForm.php | 10 +- app/modules/web/Forms/UserProfileForm.php | 10 +- app/modules/web/Init.php | 8 +- .../views/account/files-list.inc | 8 +- .../material-blue/views/itemshow/file.inc | 6 +- .../views/itemshow/item_preset.inc | 4 +- .../views/itemshow/user_profile.inc | 6 +- .../views/notification/notification.inc | 6 +- lib/SP/Core/Acl/Actions.php | 10 +- ...onData.php => ActionItemWithIdAndName.php} | 6 +- lib/SP/DataModel/FileExtData.php | 4 +- ...FileData.php => FileItemWithIdAndName.php} | 6 +- ...ItemData.php => ItemItemWithIdAndName.php} | 6 +- .../DataModel/ItemPreset/AccountPrivate.php | 14 +- ....php => NotificationItemWithIdAndName.php} | 6 +- lib/SP/DataModel/User.php | 4 +- ...a.php => UserProfileItemWithIdAndName.php} | 8 +- ...a.php => AccountPassItemWithIdAndName.php} | 6 +- .../Account/Adapters/AccountSearchItem.php | 4 +- lib/SP/Domain/Account/Dtos/AccountAclDto.php | 8 +- .../Account/Dtos/AccountEnrichedDto.php | 22 +- lib/SP/Domain/Account/Models/PublicLink.php | 6 +- .../Account/Ports/AccountFileRepository.php | 6 +- .../Account/Ports/AccountFileService.php | 8 +- .../Account/Ports/AccountToTagService.php | 6 +- .../Ports/AccountToUserGroupService.php | 6 +- .../Account/Ports/AccountToUserService.php | 6 +- lib/SP/Domain/Account/Services/Account.php | 4 +- .../Domain/Account/Services/AccountFile.php | 10 +- .../Domain/Account/Services/AccountPreset.php | 6 +- .../Domain/Account/Services/AccountToTag.php | 8 +- .../Domain/Account/Services/AccountToUser.php | 6 +- .../Account/Services/AccountToUserGroup.php | 10 +- lib/SP/Domain/Category/Models/Category.php | 4 +- lib/SP/Domain/Client/Models/Client.php | 4 +- lib/SP/Domain/Client/Ports/ClientService.php | 4 +- lib/SP/Domain/Client/Services/Client.php | 3 +- .../Domain/Common/Attributes/Hydratable.php | 51 +++ lib/SP/Domain/Common/Dtos/ItemDataTrait.php | 8 +- .../HydratableModel.php} | 23 +- .../ItemWithIdAndNameModel.php} | 10 +- lib/SP/Domain/Common/Models/Model.php | 6 +- .../Domain/Common/Models/SerializedModel.php | 51 ++- lib/SP/Domain/Core/Acl/ActionsInterface.php | 6 +- .../CustomField/Models/CustomFieldType.php | 4 +- .../Install/Services/InstallerService.php | 4 +- .../Models/ItemPreset.php | 37 +- .../ItemPreset/Ports/ItemPresetRepository.php | 76 +++- ...iceInterface.php => ItemPresetService.php} | 25 +- .../{ItemPresetService.php => ItemPreset.php} | 77 ++-- .../ItemPreset/Services/ItemPresetRequest.php | 67 ---- .../Ports/NotificationServiceInterface.php | 20 +- .../Services/NotificationService.php | 18 +- .../Plugin/Ports/PluginManagerInterface.php | 6 +- .../Domain/Plugin/Services/PluginManager.php | 4 +- lib/SP/Domain/Tag/Models/Tag.php | 4 +- lib/SP/Domain/User/Models/UserGroup.php | 4 +- .../Ports/UserProfileServiceInterface.php | 12 +- .../User/Services/UserProfileService.php | 10 +- .../Account/Repositories/AccountFile.php | 6 +- .../Account/Repositories/AccountToUser.php | 4 +- .../Repositories/AccountToUserGroup.php | 6 +- .../ItemPreset/Repositories/ItemPreset.php | 273 +++++++++++++ .../Repositories/ItemPresetBaseRepository.php | 369 ------------------ .../NotificationBaseRepository.php | 26 +- .../Repositories/PluginBaseRepository.php | 4 +- .../Plugin/Repositories/PluginDataModel.php | 6 +- .../Plugin/Repositories/PluginModel.php | 6 +- .../UserProfileBaseRepository.php | 16 +- .../Mvc/View/Components/SelectItemAdapter.php | 8 +- .../Notification/NotificationHandler.php | 12 +- lib/SP/Util/FileUtil.php | 6 +- tests/SPT/Core/Acl/ActionsTest.php | 12 +- .../Account/Adapters/AccountAdapterTest.php | 6 +- .../Account/Services/AccountAclTest.php | 10 +- .../Account/Services/AccountFileTest.php | 10 +- .../Account/Services/AccountPresetTest.php | 8 +- .../Domain/Account/Services/AccountTest.php | 12 +- .../Account/Services/AccountToTagTest.php | 4 +- .../Services/AccountToUserGroupTest.php | 8 +- .../Account/Services/AccountToUserTest.php | 8 +- .../Export/Services/XmlAccountExportTest.php | 4 +- .../ItemPreset/Services/ItemPresetTest.php | 322 +++++++++++++++ tests/SPT/Generators/AccountDataGenerator.php | 6 +- .../Generators/ItemPresetDataGenerator.php | 10 +- .../Generators/UserProfileDataGenerator.php | 6 +- .../Account/Repositories/AccountFileTest.php | 4 +- .../Repositories/AccountToUserGroupTest.php | 6 +- .../Repositories/AccountToUserTest.php | 4 +- .../Repositories/ItemPresetTest.php | 339 ++++++++++++++++ tests/SPT/UnitaryTestCase.php | 3 +- 107 files changed, 1577 insertions(+), 945 deletions(-) rename lib/SP/DataModel/{ActionData.php => ActionItemWithIdAndName.php} (88%) rename lib/SP/DataModel/{FileData.php => FileItemWithIdAndName.php} (91%) rename lib/SP/DataModel/{ItemData.php => ItemItemWithIdAndName.php} (85%) rename lib/SP/DataModel/{NotificationData.php => NotificationItemWithIdAndName.php} (95%) rename lib/SP/DataModel/{UserProfileData.php => UserProfileItemWithIdAndName.php} (85%) rename lib/SP/Domain/Account/Adapters/{AccountPassData.php => AccountPassItemWithIdAndName.php} (89%) create mode 100644 lib/SP/Domain/Common/Attributes/Hydratable.php rename lib/SP/Domain/Common/{Adapters/HydratableInterface.php => Models/HydratableModel.php} (59%) rename lib/SP/Domain/Common/{Adapters/DataModelInterface.php => Models/ItemWithIdAndNameModel.php} (81%) rename lib/SP/Domain/{Account => ItemPreset}/Models/ItemPreset.php (71%) rename lib/SP/Domain/ItemPreset/Ports/{ItemPresetServiceInterface.php => ItemPresetService.php} (80%) rename lib/SP/Domain/ItemPreset/Services/{ItemPresetService.php => ItemPreset.php} (64%) delete mode 100644 lib/SP/Domain/ItemPreset/Services/ItemPresetRequest.php create mode 100644 lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php delete mode 100644 lib/SP/Infrastructure/ItemPreset/Repositories/ItemPresetBaseRepository.php create mode 100644 tests/SPT/Domain/ItemPreset/Services/ItemPresetTest.php create mode 100644 tests/SPT/Infrastructure/ItemPreset/Repositories/ItemPresetTest.php diff --git a/app/modules/web/Controllers/Account/ViewPassController.php b/app/modules/web/Controllers/Account/ViewPassController.php index 236d1115..0ff21c10 100644 --- a/app/modules/web/Controllers/Account/ViewPassController.php +++ b/app/modules/web/Controllers/Account/ViewPassController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\WebControllerHelper; @@ -50,14 +50,14 @@ final class ViewPassController extends AccountControllerBase private AccountService $accountService; private AccountPasswordHelper $accountPasswordHelper; - private ItemPresetServiceInterface $itemPresetService; + private ItemPresetService $itemPresetService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, AccountPasswordHelper $accountPasswordHelper, - ItemPresetServiceInterface $itemPresetService + ItemPresetService $itemPresetService ) { parent::__construct( $application, diff --git a/app/modules/web/Controllers/Account/ViewPassHistoryController.php b/app/modules/web/Controllers/Account/ViewPassHistoryController.php index 29bb3ced..c25761e0 100644 --- a/app/modules/web/Controllers/Account/ViewPassHistoryController.php +++ b/app/modules/web/Controllers/Account/ViewPassHistoryController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Modules\Web\Controllers\Helpers\Account\AccountPasswordHelper; use SP\Modules\Web\Controllers\Traits\JsonTrait; use SP\Mvc\Controller\WebControllerHelper; @@ -50,14 +50,14 @@ final class ViewPassHistoryController extends AccountControllerBase private AccountService $accountService; private AccountPasswordHelper $accountPasswordHelper; - private ItemPresetServiceInterface $itemPresetService; + private ItemPresetService $itemPresetService; public function __construct( Application $application, WebControllerHelper $webControllerHelper, AccountService $accountService, AccountPasswordHelper $accountPasswordHelper, - ItemPresetServiceInterface $itemPresetService + ItemPresetService $itemPresetService ) { parent::__construct( $application, diff --git a/app/modules/web/Controllers/AccountFile/UploadController.php b/app/modules/web/Controllers/AccountFile/UploadController.php index a8e4c1f2..93ff7921 100644 --- a/app/modules/web/Controllers/AccountFile/UploadController.php +++ b/app/modules/web/Controllers/AccountFile/UploadController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -29,7 +29,7 @@ use JsonException; use SP\Core\Application; use SP\Core\Events\Event; use SP\Core\Events\EventMessage; -use SP\DataModel\FileData; +use SP\DataModel\FileItemWithIdAndName; use SP\Domain\Account\Ports\AccountFileService; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Core\Exceptions\SPException; @@ -92,7 +92,7 @@ final class UploadController extends ControllerBase try { $fileHandler = new FileHandler($file['tmp_name']); - $fileData = new FileData(); + $fileData = new FileItemWithIdAndName(); $fileData->setAccountId($accountId); $fileData->setName(htmlspecialchars($file['name'], ENT_QUOTES)); $fileData->setSize($file['size']); @@ -161,14 +161,14 @@ final class UploadController extends ControllerBase } /** - * @param FileData $fileData + * @param FileItemWithIdAndName $fileData * @param FileHandlerInterface $fileHandler * * @return string * @throws SPException * @throws FileException */ - private function checkAllowedMimeType(FileData $fileData, FileHandlerInterface $fileHandler): string + private function checkAllowedMimeType(FileItemWithIdAndName $fileData, FileHandlerInterface $fileHandler): string { if (in_array($fileData->getType(), $this->configData->getFilesAllowedMime(), true)) { return $fileData->getType(); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 91455ab4..58d599fb 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Helpers\Account; use SP\Core\Acl\Acl; use SP\Core\Application; use SP\Core\Bootstrap\BootstrapBase; -use SP\DataModel\ItemPreset\AccountPermission; +use SP\DataModel\ItemPreset\AccountPermission as AccountPermissionPreset; use SP\DataModel\ItemPreset\AccountPrivate; use SP\DataModel\ProfileData; use SP\Domain\Account\Adapters\AccountPermission; @@ -53,7 +53,7 @@ use SP\Domain\Crypt\Ports\MasterPassService; use SP\Domain\CustomField\Ports\CustomFieldDataService; use SP\Domain\Http\RequestInterface; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Domain\Tag\Ports\TagServiceInterface; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; @@ -73,39 +73,39 @@ final class AccountHelper extends AccountHelperBase { use ItemTrait; - private AccountService $accountService; - private AccountHistoryService $accountHistoryService; - private PublicLinkService $publicLinkService; - private ItemPresetServiceInterface $itemPresetService; - private MasterPassService $masterPassService; - private AccountAclService $accountAclService; - private CategoryService $categoryService; - private ClientService $clientService; - private CustomFieldDataService $customFieldService; - private ?AccountPermission $accountAcl = null; - private ?int $accountId = null; - private UserServiceInterface $userService; - private UserGroupServiceInterface $userGroupService; - private TagServiceInterface $tagService; + private AccountService $accountService; + private AccountHistoryService $accountHistoryService; + private PublicLinkService $publicLinkService; + private ItemPresetService $itemPresetService; + private MasterPassService $masterPassService; + private AccountAclService $accountAclService; + private CategoryService $categoryService; + private ClientService $clientService; + private CustomFieldDataService $customFieldService; + private ?AccountPermission $accountAcl = null; + private ?int $accountId = null; + private UserServiceInterface $userService; + private UserGroupServiceInterface $userGroupService; + private TagServiceInterface $tagService; public function __construct( - Application $application, - TemplateInterface $template, - RequestInterface $request, - AclInterface $acl, - AccountService $accountService, - AccountHistoryService $accountHistoryService, - PublicLinkService $publicLinkService, - ItemPresetServiceInterface $itemPresetService, - MasterPassService $masterPassService, - AccountActionsHelper $accountActionsHelper, - AccountAclService $accountAclService, - CategoryService $categoryService, - ClientService $clientService, - CustomFieldDataService $customFieldService, - UserServiceInterface $userService, - UserGroupServiceInterface $userGroupService, - TagServiceInterface $tagService + Application $application, + TemplateInterface $template, + RequestInterface $request, + AclInterface $acl, + AccountService $accountService, + AccountHistoryService $accountHistoryService, + PublicLinkService $publicLinkService, + ItemPresetService $itemPresetService, + MasterPassService $masterPassService, + AccountActionsHelper $accountActionsHelper, + AccountAclService $accountAclService, + CategoryService $categoryService, + ClientService $clientService, + CustomFieldDataService $customFieldService, + UserServiceInterface $userService, + UserGroupServiceInterface $userGroupService, + TagServiceInterface $tagService ) { parent::__construct($application, $template, $request, $acl, $accountActionsHelper, $masterPassService); @@ -130,7 +130,7 @@ final class AccountHelper extends AccountHelperBase * Sets account's view variables * * @param AccountEnrichedDto $accountDetailsResponse - * @param int $actionId + * @param int $actionId * * @throws AccountPermissionException * @throws UnauthorizedPageException @@ -205,8 +205,12 @@ final class AccountHelper extends AccountHelperBase ); $this->view->assign( 'historyData', - SelectItemAdapter::factory(AccountHistoryHelper::mapHistoryForDateSelect($this->accountHistoryService->getHistoryForAccount($this->accountId))) - ->getItemsFromArray() + SelectItemAdapter::factory( + AccountHistoryHelper::mapHistoryForDateSelect( + $this->accountHistoryService->getHistoryForAccount($this->accountId) + ) + ) + ->getItemsFromArray() ); $this->view->assign('isModified', strtotime($accountData->getDateEdit()) !== false); $this->view->assign('maxFileSize', round($this->configData->getFilesAllowedSize() / 1024, 1)); @@ -218,7 +222,7 @@ final class AccountHelper extends AccountHelperBase $accountActionsDto->setPublicLinkId($publicLinkData->getId()); $accountActionsDto->setPublicLinkCreatorId($publicLinkData->getUserId()); - $baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI).BootstrapBase::$SUBURI; + $baseUrl = ($this->configData->getApplicationUrl() ?: BootstrapBase::$WEBURI) . BootstrapBase::$SUBURI; $this->view->assign( 'publicLinkUrl', @@ -381,7 +385,7 @@ final class AccountHelper extends AccountHelperBase /** * Sets account's view for a blank form * - * @param int $actionId + * @param int $actionId * * @return void * @throws UnauthorizedPageException @@ -412,15 +416,17 @@ final class AccountHelper extends AccountHelperBase $accountPrivate = new AccountPrivate(); if ($itemPresetPrivate = - $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PRIVATE)) { - $accountPrivate = $itemPresetPrivate->hydrate(AccountPrivate::class) ?: $accountPrivate; + $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PRIVATE) + ) { + $accountPrivate = $itemPresetPrivate->hydrate(AccountPrivate::class) ?? $accountPrivate; } - $accountPermission = new AccountPermission(); + $accountPermission = new AccountPermissionPreset(); if ($itemPresetPermission = - $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PERMISSION)) { - $accountPermission = $itemPresetPermission->hydrate(AccountPermission::class) ?: $accountPermission; + $this->itemPresetService->getForCurrentUser(ItemPresetInterface::ITEM_TYPE_ACCOUNT_PERMISSION) + ) { + $accountPermission = $itemPresetPermission->hydrate(AccountPermissionPreset::class) ?? $accountPermission; } $selectUsers = SelectItemAdapter::factory($this->userService->getAll()); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php index 834ba08a..75199c1c 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountPasswordHelper.php @@ -32,7 +32,7 @@ use SP\Core\Acl\Acl; use SP\Core\Application; use SP\Core\Crypt\Crypt; use SP\Core\Crypt\Session as CryptSession; -use SP\Domain\Account\Adapters\AccountPassData; +use SP\Domain\Account\Adapters\AccountPassItemWithIdAndName; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\AclInterface; @@ -73,7 +73,7 @@ final class AccountPasswordHelper extends HelperBase } /** - * @param AccountPassData $accountData + * @param AccountPassItemWithIdAndName $accountData * * @param bool $useImage * @@ -88,8 +88,8 @@ final class AccountPasswordHelper extends HelperBase * @throws ServiceException */ public function getPasswordView( - AccountPassData $accountData, - bool $useImage + AccountPassItemWithIdAndName $accountData, + bool $useImage ): array { $this->checkActionAccess(); @@ -136,7 +136,7 @@ final class AccountPasswordHelper extends HelperBase /** * Returns account's password * - * @param AccountPassData $accountData + * @param AccountPassItemWithIdAndName $accountData * * @return string * @throws BadFormatException @@ -147,7 +147,7 @@ final class AccountPasswordHelper extends HelperBase * @throws NoSuchItemException * @throws ServiceException */ - public function getPasswordClear(AccountPassData $accountData): string + public function getPasswordClear(AccountPassItemWithIdAndName $accountData): string { $this->checkActionAccess(); diff --git a/app/modules/web/Controllers/Helpers/ItemPresetHelper.php b/app/modules/web/Controllers/Helpers/ItemPresetHelper.php index 01eec970..1ab7f9ef 100644 --- a/app/modules/web/Controllers/Helpers/ItemPresetHelper.php +++ b/app/modules/web/Controllers/Helpers/ItemPresetHelper.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -29,12 +29,12 @@ use SP\DataModel\ItemPreset\AccountPermission; use SP\DataModel\ItemPreset\AccountPrivate; use SP\DataModel\ItemPreset\Password; use SP\DataModel\ItemPreset\SessionTimeout; -use SP\Domain\Account\Models\ItemPreset; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\InvalidArgumentException; use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Http\RequestInterface; +use SP\Domain\ItemPreset\Models\ItemPreset; use SP\Domain\User\Ports\UserGroupServiceInterface; use SP\Domain\User\Ports\UserProfileServiceInterface; use SP\Domain\User\Ports\UserServiceInterface; diff --git a/app/modules/web/Controllers/ItemManager/IndexController.php b/app/modules/web/Controllers/ItemManager/IndexController.php index f5f4f9c0..4bd968ef 100644 --- a/app/modules/web/Controllers/ItemManager/IndexController.php +++ b/app/modules/web/Controllers/ItemManager/IndexController.php @@ -37,7 +37,7 @@ use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\CustomField\Ports\CustomFieldDefinitionService; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Domain\Tag\Ports\TagServiceInterface; use SP\Html\DataGrid\DataGridTab; use SP\Modules\Web\Controllers\ControllerBase; @@ -68,9 +68,9 @@ final class IndexController extends ControllerBase private CustomFieldDefinitionService $customFieldDefService; private AccountFileService $accountFileService; private AccountService $accountService; - private AccountHistoryService $accountHistoryService; - private ItemPresetServiceInterface $itemPresetService; - private CategoryGrid $categoryGrid; + private AccountHistoryService $accountHistoryService; + private ItemPresetService $itemPresetService; + private CategoryGrid $categoryGrid; private TagGrid $tagGrid; private ClientGrid $clientGrid; private CustomFieldGrid $customFieldGrid; @@ -90,7 +90,7 @@ final class IndexController extends ControllerBase AccountFileService $accountFileService, AccountService $accountService, AccountHistoryService $accountHistoryService, - ItemPresetServiceInterface $itemPresetService, + ItemPresetService $itemPresetService, Helpers\Grid\CategoryGrid $categoryGrid, Helpers\Grid\TagGrid $tagGrid, Helpers\Grid\ClientGrid $clientGrid, @@ -98,7 +98,7 @@ final class IndexController extends ControllerBase Helpers\Grid\FileGrid $fileGrid, Helpers\Grid\AccountGrid $accountGrid, Helpers\Grid\AccountHistoryGrid $accountHistoryGrid, - Helpers\Grid\ItemPresetGrid $itemPresetGrid + Helpers\Grid\ItemPresetGrid $itemPresetGrid ) { $this->tabsGridHelper = $tabsGridHelper; $this->categoryService = $categoryService; diff --git a/app/modules/web/Controllers/ItemPreset/ItemPresetSaveBase.php b/app/modules/web/Controllers/ItemPreset/ItemPresetSaveBase.php index 21aad467..6f5b2dfb 100644 --- a/app/modules/web/Controllers/ItemPreset/ItemPresetSaveBase.php +++ b/app/modules/web/Controllers/ItemPreset/ItemPresetSaveBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -26,7 +26,7 @@ namespace SP\Modules\Web\Controllers\ItemPreset; use SP\Core\Application; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\ItemsPresetForm; use SP\Mvc\Controller\WebControllerHelper; @@ -36,13 +36,13 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class ItemPresetSaveBase extends ControllerBase { - protected \SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface $itemPresetService; - protected ItemsPresetForm $form; + protected ItemPresetService $itemPresetService; + protected ItemsPresetForm $form; public function __construct( Application $application, WebControllerHelper $webControllerHelper, - ItemPresetServiceInterface $itemPresetService + ItemPresetService $itemPresetService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php b/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php index c304df2e..178fb982 100644 --- a/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php +++ b/app/modules/web/Controllers/ItemPreset/ItemPresetViewBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -27,14 +27,14 @@ namespace SP\Modules\Web\Controllers\ItemPreset; use SP\Core\Acl\Acl; use SP\Core\Application; -use SP\Domain\Account\Models\ItemPreset; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\InvalidArgumentException; use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\ItemPreset\Models\ItemPreset; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Controllers\Helpers\ItemPresetHelper; @@ -45,14 +45,14 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class ItemPresetViewBase extends ControllerBase { - private ItemPresetServiceInterface $itemPresetService; - private ItemPresetHelper $itemPresetHelper; + private ItemPresetService $itemPresetService; + private ItemPresetHelper $itemPresetHelper; public function __construct( - Application $application, + Application $application, WebControllerHelper $webControllerHelper, - ItemPresetServiceInterface $itemPresetService, - ItemPresetHelper $itemPresetHelper + ItemPresetService $itemPresetService, + ItemPresetHelper $itemPresetHelper ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/ItemPreset/SaveCreateController.php b/app/modules/web/Controllers/ItemPreset/SaveCreateController.php index 28a93345..15fe2b9a 100644 --- a/app/modules/web/Controllers/ItemPreset/SaveCreateController.php +++ b/app/modules/web/Controllers/ItemPreset/SaveCreateController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -67,7 +67,7 @@ final class SaveCreateController extends ItemPresetSaveBase $this, EventMessage::factory() ->addDescription(__u('Value created')) - ->addDetail(__u('Type'), $itemData->getItemPresetData()->getType()) + ->addDetail(__u('Type'), $itemData->getItemPreset()->getType()) ->addDetail(__u('ID'), $id) ) ); diff --git a/app/modules/web/Controllers/ItemPreset/SaveEditController.php b/app/modules/web/Controllers/ItemPreset/SaveEditController.php index ee113198..3e419a41 100644 --- a/app/modules/web/Controllers/ItemPreset/SaveEditController.php +++ b/app/modules/web/Controllers/ItemPreset/SaveEditController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -71,7 +71,7 @@ final class SaveEditController extends ItemPresetSaveBase $this, EventMessage::factory() ->addDescription(__u('Value updated')) - ->addDetail(__u('Type'), $itemData->getItemPresetData()->getType()) + ->addDetail(__u('Type'), $itemData->getItemPreset()->getType()) ->addDetail(__u('ID'), $id) ) ); diff --git a/app/modules/web/Controllers/ItemPreset/SearchController.php b/app/modules/web/Controllers/ItemPreset/SearchController.php index 532e0a79..4e7e1004 100644 --- a/app/modules/web/Controllers/ItemPreset/SearchController.php +++ b/app/modules/web/Controllers/ItemPreset/SearchController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -30,7 +30,7 @@ use SP\Core\Application; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Html\DataGrid\DataGridInterface; use SP\Http\JsonMessage; use SP\Modules\Web\Controllers\ControllerBase; @@ -47,14 +47,14 @@ final class SearchController extends ControllerBase use ItemTrait; use JsonTrait; - private ItemPresetServiceInterface $itemPresetService; - private ItemPresetGrid $itemPresetGrid; + private ItemPresetService $itemPresetService; + private ItemPresetGrid $itemPresetGrid; public function __construct( - Application $application, + Application $application, WebControllerHelper $webControllerHelper, - ItemPresetServiceInterface $itemPresetService, - ItemPresetGrid $itemPresetGrid + ItemPresetService $itemPresetService, + ItemPresetGrid $itemPresetGrid ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Items/NotificationsController.php b/app/modules/web/Controllers/Items/NotificationsController.php index e69c47ec..954865f0 100644 --- a/app/modules/web/Controllers/Items/NotificationsController.php +++ b/app/modules/web/Controllers/Items/NotificationsController.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Modules\Web\Controllers\Items; use SP\Core\Application; -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -65,7 +65,7 @@ final class NotificationsController extends SimpleControllerBase { $notifications = array_map( static function ($notification) { - /** @@var $notification NotificationData */ + /** @@var $notification NotificationItemWithIdAndName */ return sprintf( '(%s) - %s', $notification->getComponent(), diff --git a/app/modules/web/Controllers/Notification/NotificationViewBase.php b/app/modules/web/Controllers/Notification/NotificationViewBase.php index 3ce6a991..8d62f3f1 100644 --- a/app/modules/web/Controllers/Notification/NotificationViewBase.php +++ b/app/modules/web/Controllers/Notification/NotificationViewBase.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Notification; use SP\Core\Acl\Acl; use SP\Core\Application; -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -75,7 +75,7 @@ abstract class NotificationViewBase extends ControllerBase $notification = $notificationId ? $this->notificationService->getById($notificationId) - : new NotificationData(); + : new NotificationItemWithIdAndName(); $this->view->assign('notification', $notification); diff --git a/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php b/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php index 49e374c4..ac7246ac 100644 --- a/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php +++ b/app/modules/web/Controllers/UserProfile/UserProfileViewBase.php @@ -28,7 +28,7 @@ namespace SP\Modules\Web\Controllers\UserProfile; use SP\Core\Acl\Acl; use SP\Core\Application; use SP\DataModel\ProfileData; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; @@ -82,7 +82,7 @@ abstract class UserProfileViewBase extends ControllerBase $profile = $profileId ? $this->userProfileService->getById($profileId) - : new UserProfileData(); + : new UserProfileItemWithIdAndName(); $this->view->assign('profile', $profile); $this->view->assign('profileData', $profile->getProfile() ?: new ProfileData()); diff --git a/app/modules/web/Forms/ItemsPresetForm.php b/app/modules/web/Forms/ItemsPresetForm.php index 8171fb58..c66e3d9a 100644 --- a/app/modules/web/Forms/ItemsPresetForm.php +++ b/app/modules/web/Forms/ItemsPresetForm.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -28,10 +28,10 @@ use SP\DataModel\ItemPreset\AccountPermission; use SP\DataModel\ItemPreset\AccountPrivate; use SP\DataModel\ItemPreset\Password; use SP\DataModel\ItemPreset\SessionTimeout; -use SP\Domain\Account\Models\ItemPreset; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\InvalidArgumentException; use SP\Domain\Core\Exceptions\ValidationException; +use SP\Domain\ItemPreset\Models\ItemPreset; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; use SP\Domain\ItemPreset\Services\ItemPresetRequest; use SP\Mvc\Controller\Validators\Validator; @@ -196,7 +196,7 @@ final class ItemsPresetForm extends FormBase implements FormInterface */ protected function checkCommon(): void { - $itemPresetData = $this->itemPresetRequest->getItemPresetData(); + $itemPresetData = $this->itemPresetRequest->getItemPreset(); if (!$itemPresetData->getUserId() && !$itemPresetData->getUserGroupId() diff --git a/app/modules/web/Forms/NotificationForm.php b/app/modules/web/Forms/NotificationForm.php index 9a4b6eb5..c3316baa 100644 --- a/app/modules/web/Forms/NotificationForm.php +++ b/app/modules/web/Forms/NotificationForm.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Modules\Web\Forms; use SP\Core\Messages\NotificationMessage; -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ValidationException; @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\ValidationException; */ final class NotificationForm extends FormBase implements FormInterface { - protected ?NotificationData $notificationData = null; + protected ?NotificationItemWithIdAndName $notificationData = null; /** * Validar el formulario @@ -71,7 +71,7 @@ final class NotificationForm extends FormBase implements FormInterface */ protected function analyzeRequestData(): void { - $this->notificationData = new NotificationData(); + $this->notificationData = new NotificationItemWithIdAndName(); $this->notificationData->setId($this->itemId); $this->notificationData->setType($this->request->analyzeString('notification_type')); $this->notificationData->setComponent($this->request->analyzeString('notification_component')); @@ -113,7 +113,7 @@ final class NotificationForm extends FormBase implements FormInterface } } - public function getItemData(): ?NotificationData + public function getItemData(): ?NotificationItemWithIdAndName { return $this->notificationData; } diff --git a/app/modules/web/Forms/UserProfileForm.php b/app/modules/web/Forms/UserProfileForm.php index 956da149..759ee1a8 100644 --- a/app/modules/web/Forms/UserProfileForm.php +++ b/app/modules/web/Forms/UserProfileForm.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Modules\Web\Forms; use SP\DataModel\ProfileData; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\Core\Exceptions\ValidationException; @@ -37,7 +37,7 @@ use SP\Domain\Core\Exceptions\ValidationException; */ final class UserProfileForm extends FormBase implements FormInterface { - protected ?UserProfileData $userProfileData = null; + protected ?UserProfileItemWithIdAndName $userProfileData = null; /** * Validar el formulario @@ -74,7 +74,7 @@ final class UserProfileForm extends FormBase implements FormInterface { $profileData = $this->getProfileDataFromRequest(); - $this->userProfileData = new UserProfileData(); + $this->userProfileData = new UserProfileItemWithIdAndName(); $this->userProfileData->setName($this->request->analyzeString('profile_name')); $this->userProfileData->setId($this->itemId); $this->userProfileData->setProfile($profileData); @@ -133,7 +133,7 @@ final class UserProfileForm extends FormBase implements FormInterface /** * @throws SPException */ - public function getItemData(): UserProfileData + public function getItemData(): UserProfileItemWithIdAndName { if (null === $this->userProfileData) { throw new SPException(__u('Profile data not set')); diff --git a/app/modules/web/Init.php b/app/modules/web/Init.php index 3b7ef468..3aff25ab 100644 --- a/app/modules/web/Init.php +++ b/app/modules/web/Init.php @@ -53,7 +53,7 @@ use SP\Domain\Crypt\Ports\SecureSessionService; use SP\Domain\Crypt\Services\SecureSession; use SP\Domain\Http\RequestInterface; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Services\ItemPresetService; +use SP\Domain\ItemPreset\Services\ItemPreset; use SP\Domain\Upgrade\Services\UpgradeAppService; use SP\Domain\Upgrade\Services\UpgradeDatabaseService; use SP\Domain\Upgrade\Services\UpgradeUtil; @@ -140,8 +140,8 @@ final class Init extends HttpModuleBase private Language $language; private SecureSession $secureSessionService; private PluginManager $pluginManager; - private ItemPresetService $itemPresetService; - private DatabaseUtil $databaseUtil; + private ItemPreset $itemPresetService; + private DatabaseUtil $databaseUtil; private UserProfileService $userProfileService; private bool $isIndex = false; @@ -154,7 +154,7 @@ final class Init extends HttpModuleBase LanguageInterface $language, SecureSessionService $secureSessionService, PluginManager $pluginManager, - ItemPresetService $itemPresetService, + ItemPreset $itemPresetService, DatabaseUtil $databaseUtil, UserProfileServiceInterface $userProfileService, private readonly UriContextInterface $uriContext diff --git a/app/modules/web/themes/material-blue/views/account/files-list.inc b/app/modules/web/themes/material-blue/views/account/files-list.inc index c8509f5b..0c4a2158 100644 --- a/app/modules/web/themes/material-blue/views/account/files-list.inc +++ b/app/modules/web/themes/material-blue/views/account/files-list.inc @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -23,13 +23,13 @@ */ /** - * @var \SP\Domain\Core\UI\ThemeIconsInterface $icons + * @var ThemeIconsInterface $icons * @var callable $_getvar * @var ConfigDataInterface $configData - * @var FileData $file + * @var FileItemWithIdAndName $file */ -use SP\DataModel\FileData; +use SP\DataModel\FileItemWithIdAndName; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Core\UI\ThemeIconsInterface; use SP\Html\Html; diff --git a/app/modules/web/themes/material-blue/views/itemshow/file.inc b/app/modules/web/themes/material-blue/views/itemshow/file.inc index a3950115..b47d53e6 100644 --- a/app/modules/web/themes/material-blue/views/itemshow/file.inc +++ b/app/modules/web/themes/material-blue/views/itemshow/file.inc @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -23,14 +23,14 @@ */ /** - * @var FileData $fileData + * @var FileItemWithIdAndName $fileData * @var ThemeIconsInterface $icons * @var ConfigDataInterface $configData * @var callable $_getvar * @var TemplateInterface $this */ -use SP\DataModel\FileData; +use SP\DataModel\FileItemWithIdAndName; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Core\UI\ThemeIconsInterface; use SP\Mvc\View\TemplateInterface; diff --git a/app/modules/web/themes/material-blue/views/itemshow/item_preset.inc b/app/modules/web/themes/material-blue/views/itemshow/item_preset.inc index a64d5519..43be8c1c 100644 --- a/app/modules/web/themes/material-blue/views/itemshow/item_preset.inc +++ b/app/modules/web/themes/material-blue/views/itemshow/item_preset.inc @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -30,9 +30,9 @@ * @var TemplateInterface $this */ -use SP\Domain\Account\Models\ItemPreset; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Core\UI\ThemeIconsInterface; +use SP\Domain\ItemPreset\Models\ItemPreset; use SP\Mvc\View\Components\SelectItem; use SP\Mvc\View\TemplateInterface; diff --git a/app/modules/web/themes/material-blue/views/itemshow/user_profile.inc b/app/modules/web/themes/material-blue/views/itemshow/user_profile.inc index 3d371636..e5558eb9 100644 --- a/app/modules/web/themes/material-blue/views/itemshow/user_profile.inc +++ b/app/modules/web/themes/material-blue/views/itemshow/user_profile.inc @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ /** * @var ProfileData $profileData - * @var UserProfileData $profile + * @var UserProfileItemWithIdAndName $profile * @var ThemeIconsInterface $icons * @var ConfigDataInterface $configData * @var callable $_getvar @@ -32,7 +32,7 @@ */ use SP\DataModel\ProfileData; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Core\UI\ThemeIconsInterface; use SP\Mvc\View\TemplateInterface; diff --git a/app/modules/web/themes/material-blue/views/notification/notification.inc b/app/modules/web/themes/material-blue/views/notification/notification.inc index d148cf2c..3d08506e 100644 --- a/app/modules/web/themes/material-blue/views/notification/notification.inc +++ b/app/modules/web/themes/material-blue/views/notification/notification.inc @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -23,14 +23,14 @@ */ /** - * @var NotificationData $notification + * @var NotificationItemWithIdAndName $notification * @var ThemeIconsInterface $icons * @var ConfigDataInterface $configData * @var callable $_getvar * @var TemplateInterface $this */ -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Core\UI\ThemeIconsInterface; use SP\Mvc\View\Components\SelectItem; diff --git a/lib/SP/Core/Acl/Actions.php b/lib/SP/Core/Acl/Actions.php index fa778b96..80cfcaec 100644 --- a/lib/SP/Core/Acl/Actions.php +++ b/lib/SP/Core/Acl/Actions.php @@ -24,7 +24,7 @@ namespace SP\Core\Acl; -use SP\DataModel\ActionData; +use SP\DataModel\ActionItemWithIdAndName; use SP\Domain\Core\Acl\ActionNotFoundException; use SP\Domain\Core\Acl\ActionsInterface; use SP\Domain\Storage\Ports\FileCacheService; @@ -49,7 +49,7 @@ class Actions implements ActionsInterface */ public const CACHE_EXPIRE = 86400; /** - * @var ActionData[]|null + * @var ActionItemWithIdAndName[]|null */ protected ?array $actions = null; @@ -113,14 +113,14 @@ class Actions implements ActionsInterface $this->actions = []; foreach ($this->load() as $a) { - $this->actions[$a['id']] = new ActionData($a['id'], $a['name'], $a['text'], $a['route']); + $this->actions[$a['id']] = new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']); } } /** * Loads actions from DB * - * @return ActionData[] + * @return ActionItemWithIdAndName[] * @throws FileException */ protected function load(): array @@ -147,7 +147,7 @@ class Actions implements ActionsInterface * * @throws ActionNotFoundException */ - public function getActionById(int $id): ActionData + public function getActionById(int $id): ActionItemWithIdAndName { if (!isset($this->actions[$id])) { throw new ActionNotFoundException(__u('Action not found')); diff --git a/lib/SP/DataModel/ActionData.php b/lib/SP/DataModel/ActionItemWithIdAndName.php similarity index 88% rename from lib/SP/DataModel/ActionData.php rename to lib/SP/DataModel/ActionItemWithIdAndName.php index d49ae6c6..65eaa9a5 100644 --- a/lib/SP/DataModel/ActionData.php +++ b/lib/SP/DataModel/ActionItemWithIdAndName.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,14 +24,14 @@ namespace SP\DataModel; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; /** * Class ActionData * * @package SP\DataModel */ -class ActionData implements DataModelInterface +class ActionItemWithIdAndName implements ItemWithIdAndNameModel { public function __construct( private readonly int $id, diff --git a/lib/SP/DataModel/FileExtData.php b/lib/SP/DataModel/FileExtData.php index f0022815..6018f854 100644 --- a/lib/SP/DataModel/FileExtData.php +++ b/lib/SP/DataModel/FileExtData.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -29,7 +29,7 @@ namespace SP\DataModel; * * @package SP\DataModel */ -class FileExtData extends FileData +class FileExtData extends FileItemWithIdAndName { protected ?string $clientName = null; protected ?string $accountName = null; diff --git a/lib/SP/DataModel/FileData.php b/lib/SP/DataModel/FileItemWithIdAndName.php similarity index 91% rename from lib/SP/DataModel/FileData.php rename to lib/SP/DataModel/FileItemWithIdAndName.php index b5c1ce3f..7e1712e4 100644 --- a/lib/SP/DataModel/FileData.php +++ b/lib/SP/DataModel/FileItemWithIdAndName.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\DataModel; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** @@ -32,7 +32,7 @@ use SP\Domain\Common\Models\Model; * * @package SP\DataModel */ -class FileData extends Model implements DataModelInterface +class FileItemWithIdAndName extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?int $accountId = null; diff --git a/lib/SP/DataModel/ItemData.php b/lib/SP/DataModel/ItemItemWithIdAndName.php similarity index 85% rename from lib/SP/DataModel/ItemData.php rename to lib/SP/DataModel/ItemItemWithIdAndName.php index 0a4eb52b..480fdfb8 100644 --- a/lib/SP/DataModel/ItemData.php +++ b/lib/SP/DataModel/ItemItemWithIdAndName.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\DataModel; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** @@ -32,7 +32,7 @@ use SP\Domain\Common\Models\Model; * * @package SP\DataModel */ -class ItemData extends Model implements DataModelInterface +class ItemItemWithIdAndName extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; diff --git a/lib/SP/DataModel/ItemPreset/AccountPrivate.php b/lib/SP/DataModel/ItemPreset/AccountPrivate.php index 61b3592a..193e5a3c 100644 --- a/lib/SP/DataModel/ItemPreset/AccountPrivate.php +++ b/lib/SP/DataModel/ItemPreset/AccountPrivate.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -31,14 +31,10 @@ namespace SP\DataModel\ItemPreset; */ final class AccountPrivate { - /** - * @param bool|null $privateUser - * @param bool|null $privateGroup - */ - public function __construct(private ?bool $privateUser = false, private ?bool $privateGroup = false) - { - $this->privateUser = $privateUser; - $this->privateGroup = $privateGroup; + public function __construct( + private readonly ?bool $privateUser = false, + private readonly ?bool $privateGroup = false + ) { } public function isPrivateUser(): bool diff --git a/lib/SP/DataModel/NotificationData.php b/lib/SP/DataModel/NotificationItemWithIdAndName.php similarity index 95% rename from lib/SP/DataModel/NotificationData.php rename to lib/SP/DataModel/NotificationItemWithIdAndName.php index 77d3e11a..18f7077b 100644 --- a/lib/SP/DataModel/NotificationData.php +++ b/lib/SP/DataModel/NotificationItemWithIdAndName.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\DataModel; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Core\Messages\MessageInterface; /** @@ -32,7 +32,7 @@ use SP\Domain\Core\Messages\MessageInterface; * * @package SP\DataModel */ -class NotificationData implements DataModelInterface +class NotificationItemWithIdAndName implements ItemWithIdAndNameModel { /** * @var int diff --git a/lib/SP/DataModel/User.php b/lib/SP/DataModel/User.php index e65aff0f..984cd51f 100644 --- a/lib/SP/DataModel/User.php +++ b/lib/SP/DataModel/User.php @@ -24,14 +24,14 @@ namespace SP\DataModel; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; /** * Class UserBasicData * * @package SP\DataModel */ -class User extends UserPassData implements DataModelInterface +class User extends UserPassData implements ItemWithIdAndNameModel { protected ?string $login = null; protected ?string $ssoLogin = null; diff --git a/lib/SP/DataModel/UserProfileData.php b/lib/SP/DataModel/UserProfileItemWithIdAndName.php similarity index 85% rename from lib/SP/DataModel/UserProfileData.php rename to lib/SP/DataModel/UserProfileItemWithIdAndName.php index 5685a6e0..6e782b2a 100644 --- a/lib/SP/DataModel/UserProfileData.php +++ b/lib/SP/DataModel/UserProfileItemWithIdAndName.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\DataModel; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; defined('APP_ROOT') || die(); @@ -34,7 +34,7 @@ defined('APP_ROOT') || die(); * * @package SP\DataModel */ -class UserProfileData extends Model implements DataModelInterface +class UserProfileItemWithIdAndName extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; @@ -57,7 +57,7 @@ class UserProfileData extends Model implements DataModelInterface } /** - * @return \SP\DataModel\ProfileData|null + * @return ProfileData|null */ public function getProfile(): ?ProfileData { diff --git a/lib/SP/Domain/Account/Adapters/AccountPassData.php b/lib/SP/Domain/Account/Adapters/AccountPassItemWithIdAndName.php similarity index 89% rename from lib/SP/Domain/Account/Adapters/AccountPassData.php rename to lib/SP/Domain/Account/Adapters/AccountPassItemWithIdAndName.php index 499156a7..5093263e 100644 --- a/lib/SP/Domain/Account/Adapters/AccountPassData.php +++ b/lib/SP/Domain/Account/Adapters/AccountPassItemWithIdAndName.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,13 +24,13 @@ namespace SP\Domain\Account\Adapters; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class AccountPassData */ -class AccountPassData extends Model implements DataModelInterface +class AccountPassItemWithIdAndName extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; diff --git a/lib/SP/Domain/Account/Adapters/AccountSearchItem.php b/lib/SP/Domain/Account/Adapters/AccountSearchItem.php index 9c0124d3..69ff8e6a 100644 --- a/lib/SP/Domain/Account/Adapters/AccountSearchItem.php +++ b/lib/SP/Domain/Account/Adapters/AccountSearchItem.php @@ -25,7 +25,7 @@ namespace SP\Domain\Account\Adapters; use SP\Core\Bootstrap\BootstrapBase; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Models\AccountSearchView; use SP\Domain\Account\Services\PublicLink; use SP\Domain\Common\Dtos\ItemDataTrait; @@ -246,7 +246,7 @@ final class AccountSearchItem } /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] */ public function getTags(): array { diff --git a/lib/SP/Domain/Account/Dtos/AccountAclDto.php b/lib/SP/Domain/Account/Dtos/AccountAclDto.php index 14771447..db4c257a 100644 --- a/lib/SP/Domain/Account/Dtos/AccountAclDto.php +++ b/lib/SP/Domain/Account/Dtos/AccountAclDto.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Account\Dtos; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Models\AccountSearchView; use SP\Domain\Common\Dtos\ItemDataTrait; @@ -110,7 +110,7 @@ final class AccountAclDto } /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] */ public function getUsersId(): array { @@ -118,7 +118,7 @@ final class AccountAclDto } /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] */ public function getUserGroupsId(): array { diff --git a/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php b/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php index b405a2c9..090f51e6 100644 --- a/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php +++ b/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Account\Dtos; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Models\AccountView; use SP\Domain\Common\Dtos\ItemDataTrait; @@ -37,15 +37,15 @@ class AccountEnrichedDto private readonly int $id; /** - * @var ItemData[] Los usuarios secundarios de la cuenta. + * @var ItemItemWithIdAndName[] Los usuarios secundarios de la cuenta. */ private array $users = []; /** - * @var ItemData[] Los grupos secundarios de la cuenta. + * @var ItemItemWithIdAndName[] Los grupos secundarios de la cuenta. */ private array $userGroups = []; /** - * @var ItemData[] Las etiquetas de la cuenta. + * @var ItemItemWithIdAndName[] Las etiquetas de la cuenta. */ private array $tags = []; @@ -68,7 +68,7 @@ class AccountEnrichedDto } /** - * @param ItemData[] $users + * @param ItemItemWithIdAndName[] $users * * @return AccountEnrichedDto */ @@ -81,7 +81,7 @@ class AccountEnrichedDto } /** - * @param ItemData[] $groups + * @param ItemItemWithIdAndName[] $groups * * @return AccountEnrichedDto */ @@ -94,7 +94,7 @@ class AccountEnrichedDto } /** - * @param ItemData[] $tags + * @param ItemItemWithIdAndName[] $tags * * @return AccountEnrichedDto */ @@ -107,7 +107,7 @@ class AccountEnrichedDto } /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] */ public function getUsers(): array { @@ -115,7 +115,7 @@ class AccountEnrichedDto } /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] */ public function getUserGroups(): array { @@ -123,7 +123,7 @@ class AccountEnrichedDto } /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] */ public function getTags(): array { diff --git a/lib/SP/Domain/Account/Models/PublicLink.php b/lib/SP/Domain/Account/Models/PublicLink.php index 07cc71b7..f0443150 100644 --- a/lib/SP/Domain/Account/Models/PublicLink.php +++ b/lib/SP/Domain/Account/Models/PublicLink.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,13 +24,13 @@ namespace SP\Domain\Account\Models; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class PublicLink */ -class PublicLink extends Model implements DataModelInterface +class PublicLink extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?int $itemId = null; diff --git a/lib/SP/Domain/Account/Ports/AccountFileRepository.php b/lib/SP/Domain/Account/Ports/AccountFileRepository.php index 27f2d858..df0ee8f0 100644 --- a/lib/SP/Domain/Account/Ports/AccountFileRepository.php +++ b/lib/SP/Domain/Account/Ports/AccountFileRepository.php @@ -24,7 +24,7 @@ namespace SP\Domain\Account\Ports; -use SP\DataModel\FileData; +use SP\DataModel\FileItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Common\Ports\Repository; use SP\Domain\Core\Exceptions\ConstraintException; @@ -41,13 +41,13 @@ interface AccountFileRepository extends Repository /** * Creates an item * - * @param FileData $fileData + * @param FileItemWithIdAndName $fileData * * @return int * @throws ConstraintException * @throws QueryException */ - public function create(FileData $fileData): int; + public function create(FileItemWithIdAndName $fileData): int; /** * Returns the item for given id diff --git a/lib/SP/Domain/Account/Ports/AccountFileService.php b/lib/SP/Domain/Account/Ports/AccountFileService.php index 58f4cd7a..dbcc55dd 100644 --- a/lib/SP/Domain/Account/Ports/AccountFileService.php +++ b/lib/SP/Domain/Account/Ports/AccountFileService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,8 +24,8 @@ namespace SP\Domain\Account\Ports; -use SP\DataModel\FileData; use SP\DataModel\FileExtData; +use SP\DataModel\FileItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; @@ -48,7 +48,7 @@ interface AccountFileService * @throws ConstraintException * @throws QueryException */ - public function create(FileData $itemData): int; + public function create(FileItemWithIdAndName $itemData): int; /** * Returns the item for given id @@ -92,7 +92,7 @@ interface AccountFileService /** * Returns the item for given id * - * @return FileData[] + * @return FileItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Domain/Account/Ports/AccountToTagService.php b/lib/SP/Domain/Account/Ports/AccountToTagService.php index 322c0b73..dc86b7bd 100644 --- a/lib/SP/Domain/Account/Ports/AccountToTagService.php +++ b/lib/SP/Domain/Account/Ports/AccountToTagService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Account\Ports; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -36,7 +36,7 @@ use SP\Domain\Core\Exceptions\QueryException; interface AccountToTagService { /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Domain/Account/Ports/AccountToUserGroupService.php b/lib/SP/Domain/Account/Ports/AccountToUserGroupService.php index 5351f109..9c532eb8 100644 --- a/lib/SP/Domain/Account/Ports/AccountToUserGroupService.php +++ b/lib/SP/Domain/Account/Ports/AccountToUserGroupService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Account\Ports; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -37,7 +37,7 @@ interface AccountToUserGroupService /** * @param int $id * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws ConstraintException * @throws QueryException * @throws SPException diff --git a/lib/SP/Domain/Account/Ports/AccountToUserService.php b/lib/SP/Domain/Account/Ports/AccountToUserService.php index c7ff0fc9..c1be77c6 100644 --- a/lib/SP/Domain/Account/Ports/AccountToUserService.php +++ b/lib/SP/Domain/Account/Ports/AccountToUserService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Account\Ports; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -37,7 +37,7 @@ interface AccountToUserService /** * @param int $id * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws ConstraintException * @throws QueryException * @throws SPException diff --git a/lib/SP/Domain/Account/Services/Account.php b/lib/SP/Domain/Account/Services/Account.php index 399b47e1..8d7db962 100644 --- a/lib/SP/Domain/Account/Services/Account.php +++ b/lib/SP/Domain/Account/Services/Account.php @@ -55,7 +55,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Domain\User\Services\UserLoginResponse; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Infrastructure\Database\QueryResult; @@ -75,7 +75,7 @@ final class Account extends Service implements AccountService private readonly AccountToUserGroupRepository $accountToUserGroupRepository, private readonly AccountToUserRepository $accountToUserRepository, private readonly AccountToTagRepository $accountToTagRepository, - private readonly ItemPresetServiceInterface $itemPresetService, + private readonly ItemPresetService $itemPresetService, private readonly AccountHistoryService $accountHistoryService, private readonly AccountItemsService $accountItemsService, private readonly AccountPresetService $accountPresetService, diff --git a/lib/SP/Domain/Account/Services/AccountFile.php b/lib/SP/Domain/Account/Services/AccountFile.php index 7d0776ff..8972b072 100644 --- a/lib/SP/Domain/Account/Services/AccountFile.php +++ b/lib/SP/Domain/Account/Services/AccountFile.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,8 +25,8 @@ namespace SP\Domain\Account\Services; use SP\Core\Application; -use SP\DataModel\FileData; use SP\DataModel\FileExtData; +use SP\DataModel\FileItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Account\Ports\AccountFileRepository; use SP\Domain\Account\Ports\AccountFileService; @@ -62,14 +62,14 @@ final class AccountFile extends Service implements AccountFileService /** * Creates an item * - * @param FileData $itemData + * @param FileItemWithIdAndName $itemData * * @return int * @throws ConstraintException * @throws InvalidImageException * @throws QueryException */ - public function create(FileData $itemData): int + public function create(FileItemWithIdAndName $itemData): int { if (FileUtil::isImage($itemData)) { $itemData->setThumb($this->imageUtil->createThumbnail($itemData->getContent())); @@ -152,7 +152,7 @@ final class AccountFile extends Service implements AccountFileService * Returns the item for given id * * @param int $id - * @return FileData[] + * @return FileItemWithIdAndName[] * @throws ConstraintException * @throws QueryException * @throws SPException diff --git a/lib/SP/Domain/Account/Services/AccountPreset.php b/lib/SP/Domain/Account/Services/AccountPreset.php index 7f1af9e8..fd38e0a6 100644 --- a/lib/SP/Domain/Account/Services/AccountPreset.php +++ b/lib/SP/Domain/Account/Services/AccountPreset.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -38,7 +38,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\ValidationException; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Mvc\Controller\Validators\ValidatorInterface; /** @@ -50,7 +50,7 @@ final class AccountPreset extends Service implements AccountPresetService { public function __construct( Application $application, - private readonly ItemPresetServiceInterface $itemPresetService, + private readonly ItemPresetService $itemPresetService, private readonly AccountToUserGroupRepository $accountToUserGroupRepository, private readonly AccountToUserRepository $accountToUserRepository, private readonly ConfigDataInterface $configData, diff --git a/lib/SP/Domain/Account/Services/AccountToTag.php b/lib/SP/Domain/Account/Services/AccountToTag.php index b567dd65..96091618 100644 --- a/lib/SP/Domain/Account/Services/AccountToTag.php +++ b/lib/SP/Domain/Account/Services/AccountToTag.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Domain\Account\Services; use SP\Core\Application; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToTagRepository; use SP\Domain\Account\Ports\AccountToTagService; use SP\Domain\Common\Models\Simple; @@ -52,7 +52,7 @@ final class AccountToTag extends Service implements AccountToTagService /** * @param int $id * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * * @throws ConstraintException * @throws QueryException @@ -64,6 +64,6 @@ final class AccountToTag extends Service implements AccountToTagService ->getTagsByAccountId($id) ->getDataAsArray(Simple::class); - return array_map(fn($tag) => ItemData::buildFromSimpleModel($tag), $tags); + return array_map(fn($tag) => ItemItemWithIdAndName::buildFromSimpleModel($tag), $tags); } } diff --git a/lib/SP/Domain/Account/Services/AccountToUser.php b/lib/SP/Domain/Account/Services/AccountToUser.php index dde0f9a9..619ed288 100644 --- a/lib/SP/Domain/Account/Services/AccountToUser.php +++ b/lib/SP/Domain/Account/Services/AccountToUser.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Domain\Account\Services; use SP\Core\Application; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToUserRepository; use SP\Domain\Account\Ports\AccountToUserService; use SP\Domain\Common\Services\Service; @@ -48,7 +48,7 @@ final class AccountToUser extends Service implements AccountToUserService /** * @param int $id * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws ConstraintException * @throws QueryException * @throws SPException diff --git a/lib/SP/Domain/Account/Services/AccountToUserGroup.php b/lib/SP/Domain/Account/Services/AccountToUserGroup.php index ad30e391..391a1741 100644 --- a/lib/SP/Domain/Account/Services/AccountToUserGroup.php +++ b/lib/SP/Domain/Account/Services/AccountToUserGroup.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Domain\Account\Services; use SP\Core\Application; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToUserGroupRepository; use SP\Domain\Account\Ports\AccountToUserGroupService; use SP\Domain\Common\Services\Service; @@ -48,13 +48,15 @@ final class AccountToUserGroup extends Service implements AccountToUserGroupServ /** * @param int $id * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws ConstraintException * @throws QueryException * @throws SPException */ public function getUserGroupsByAccountId(int $id): array { - return $this->accountToUserGroupRepository->getUserGroupsByAccountId($id)->getDataAsArray(ItemData::class); + return $this->accountToUserGroupRepository->getUserGroupsByAccountId($id)->getDataAsArray( + ItemItemWithIdAndName::class + ); } } diff --git a/lib/SP/Domain/Category/Models/Category.php b/lib/SP/Domain/Category/Models/Category.php index c81a8e98..8f5826d2 100644 --- a/lib/SP/Domain/Category/Models/Category.php +++ b/lib/SP/Domain/Category/Models/Category.php @@ -24,13 +24,13 @@ namespace SP\Domain\Category\Models; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class Category */ -class Category extends Model implements DataModelInterface +class Category extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; diff --git a/lib/SP/Domain/Client/Models/Client.php b/lib/SP/Domain/Client/Models/Client.php index e139bd2c..66d86b60 100644 --- a/lib/SP/Domain/Client/Models/Client.php +++ b/lib/SP/Domain/Client/Models/Client.php @@ -24,13 +24,13 @@ namespace SP\Domain\Client\Models; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class Client */ -class Client extends Model implements DataModelInterface +class Client extends Model implements ItemWithIdAndNameModel { protected ?int $isGlobal = null; protected ?int $id = null; diff --git a/lib/SP/Domain/Client/Ports/ClientService.php b/lib/SP/Domain/Client/Ports/ClientService.php index fd369039..81e41301 100644 --- a/lib/SP/Domain/Client/Ports/ClientService.php +++ b/lib/SP/Domain/Client/Ports/ClientService.php @@ -24,7 +24,7 @@ namespace SP\Domain\Client\Ports; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Client\Models\Client; use SP\Domain\Common\Services\ServiceException; @@ -106,7 +106,7 @@ interface ClientService /** * Returns all clients visible for a given user * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws QueryException * @throws ConstraintException */ diff --git a/lib/SP/Domain/Client/Services/Client.php b/lib/SP/Domain/Client/Services/Client.php index 933bf659..192d5d65 100644 --- a/lib/SP/Domain/Client/Services/Client.php +++ b/lib/SP/Domain/Client/Services/Client.php @@ -60,7 +60,7 @@ final class Client extends Service implements ClientService /** * @param ItemSearchData $itemSearchData * - * @return QueryResult + * @return QueryResult */ public function search(ItemSearchData $itemSearchData): QueryResult { @@ -169,7 +169,6 @@ final class Client extends Service implements ClientService * Get all items from the service's repository * * @return array - * @throws SPException */ public function getAll(): array { diff --git a/lib/SP/Domain/Common/Attributes/Hydratable.php b/lib/SP/Domain/Common/Attributes/Hydratable.php new file mode 100644 index 00000000..36cbe2e0 --- /dev/null +++ b/lib/SP/Domain/Common/Attributes/Hydratable.php @@ -0,0 +1,51 @@ +. + */ + +namespace SP\Domain\Common\Attributes; + +use Attribute; + +/** + * Class Hydratable + */ +#[Attribute(Attribute::TARGET_CLASS)] +final class Hydratable +{ + private readonly array $targetClass; + + public function __construct(private readonly string $sourceProperty, array $targetClass) + { + $this->targetClass = array_filter($targetClass, static fn(string $class) => class_exists($class)); + } + + public function getTargetClass(): array + { + return $this->targetClass; + } + + public function getSourceProperty(): string + { + return $this->sourceProperty; + } +} diff --git a/lib/SP/Domain/Common/Dtos/ItemDataTrait.php b/lib/SP/Domain/Common/Dtos/ItemDataTrait.php index 18a0753e..6b17a9b7 100644 --- a/lib/SP/Domain/Common/Dtos/ItemDataTrait.php +++ b/lib/SP/Domain/Common/Dtos/ItemDataTrait.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Common\Dtos; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; /** * Trait ItemDataTrait @@ -32,12 +32,12 @@ use SP\DataModel\ItemData; trait ItemDataTrait { /** - * @param ItemData[] $items + * @param ItemItemWithIdAndName[] $items * * @return array */ private static function buildFromItemData(array $items): array { - return array_filter($items, static fn($value) => $value instanceof ItemData); + return array_filter($items, static fn($value) => $value instanceof ItemItemWithIdAndName); } } diff --git a/lib/SP/Domain/Common/Adapters/HydratableInterface.php b/lib/SP/Domain/Common/Models/HydratableModel.php similarity index 59% rename from lib/SP/Domain/Common/Adapters/HydratableInterface.php rename to lib/SP/Domain/Common/Models/HydratableModel.php index bacce3ae..ff8934f9 100644 --- a/lib/SP/Domain/Common/Adapters/HydratableInterface.php +++ b/lib/SP/Domain/Common/Models/HydratableModel.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -22,19 +22,28 @@ * along with sysPass. If not, see . */ -namespace SP\Domain\Common\Adapters; +namespace SP\Domain\Common\Models; /** - * Interface HydratableInterface + * Interface HydratableModel */ -interface HydratableInterface +interface HydratableModel { /** + * Deserialize the hydratable property and returns the object. + * * @template T - * @param class-string|null $class - * @param string $property + * @param class-string $class * * @return T|null */ - public function hydrate(?string $class = null, string $property = 'data'): mixed; + public function hydrate(string $class): ?object; + + /** + * Serialize the object in the hydratable property + * @param object $object + * + * @return static A new instance of the model with the serialized property + */ + public function dehydrate(object $object): static; } diff --git a/lib/SP/Domain/Common/Adapters/DataModelInterface.php b/lib/SP/Domain/Common/Models/ItemWithIdAndNameModel.php similarity index 81% rename from lib/SP/Domain/Common/Adapters/DataModelInterface.php rename to lib/SP/Domain/Common/Models/ItemWithIdAndNameModel.php index 18cd2e1a..f175f731 100644 --- a/lib/SP/Domain/Common/Adapters/DataModelInterface.php +++ b/lib/SP/Domain/Common/Models/ItemWithIdAndNameModel.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -22,14 +22,12 @@ * along with sysPass. If not, see . */ -namespace SP\Domain\Common\Adapters; +namespace SP\Domain\Common\Models; /** - * Interface DataModelInterface - * - * @package SP\DataModel + * Interface ItemWithIdAndNameModel */ -interface DataModelInterface +interface ItemWithIdAndNameModel { public function getId(): ?int; diff --git a/lib/SP/Domain/Common/Models/Model.php b/lib/SP/Domain/Common/Models/Model.php index 1f117df1..fd4b748f 100644 --- a/lib/SP/Domain/Common/Models/Model.php +++ b/lib/SP/Domain/Common/Models/Model.php @@ -61,7 +61,7 @@ abstract class Model implements JsonSerializable, ArrayAccess { return array_filter( get_object_vars($this), - fn($key) => $key !== 'properties' && $key !== 'fields', + static fn(string $key) => $key !== 'properties' && $key !== 'fields', ARRAY_FILTER_USE_KEY ); } @@ -118,9 +118,7 @@ abstract class Model implements JsonSerializable, ArrayAccess */ final public static function getCols(?array $exclude = null): array { - $self = new static(); - - return array_keys($self->toArray(null, $exclude)); + return array_keys((new static())->toArray(null, $exclude)); } /** diff --git a/lib/SP/Domain/Common/Models/SerializedModel.php b/lib/SP/Domain/Common/Models/SerializedModel.php index 6ade0c9d..9a1ead3b 100644 --- a/lib/SP/Domain/Common/Models/SerializedModel.php +++ b/lib/SP/Domain/Common/Models/SerializedModel.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,37 +24,52 @@ namespace SP\Domain\Common\Models; -use SP\Domain\Core\Exceptions\NoSuchPropertyException; -use SP\Util\Util; +use ReflectionClass; +use SP\Domain\Common\Attributes\Hydratable; /** - * Trait Datamodel + * Trait SerializedModel */ trait SerializedModel { /** * @template THydrate - * @param class-string|null $class - * @param string $property + * @param class-string $class * * @return THydrate|null - * @throws NoSuchPropertyException */ - public function hydrate(?string $class = null, string $property = 'data'): mixed + public function hydrate(string $class): ?object { - if (property_exists($this, $property)) { - if ($this->{$property} === null) { - return null; - } + $reflectionClass = new ReflectionClass($this); - if ($class !== null) { - return Util::unserialize($class, $this->{$property}); - } + foreach ($reflectionClass->getAttributes(Hydratable::class) as $attribute) { + /** @var Hydratable $instance */ + $instance = $attribute->newInstance(); - /** @noinspection UnserializeExploitsInspection */ - return unserialize($this->{$property}); + if (in_array($class, $instance->getTargetClass()) && $this->{$instance->getSourceProperty()} !== null) { + return unserialize($this->{$instance->getSourceProperty()}, ['allowed_classes' => [$class]]) ?: null; + } } - throw new NoSuchPropertyException($property); + return null; + } + + /** + * @inheritDoc + */ + public function dehydrate(object $object): static + { + $reflectionClass = new ReflectionClass($this); + + foreach ($reflectionClass->getAttributes(Hydratable::class) as $attribute) { + /** @var Hydratable $instance */ + $instance = $attribute->newInstance(); + + if (in_array($object::class, $instance->getTargetClass())) { + return $this->mutate([$instance->getSourceProperty() => serialize($object)]); + } + } + + return $this; } } diff --git a/lib/SP/Domain/Core/Acl/ActionsInterface.php b/lib/SP/Domain/Core/Acl/ActionsInterface.php index f71f882a..f7d34b71 100644 --- a/lib/SP/Domain/Core/Acl/ActionsInterface.php +++ b/lib/SP/Domain/Core/Acl/ActionsInterface.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Core\Acl; -use SP\DataModel\ActionData; +use SP\DataModel\ActionItemWithIdAndName; use SP\Infrastructure\File\FileException; /** @@ -37,7 +37,7 @@ interface ActionsInterface * * @throws ActionNotFoundException */ - public function getActionById(int $id): ActionData; + public function getActionById(int $id): ActionItemWithIdAndName; /** * @throws FileException diff --git a/lib/SP/Domain/CustomField/Models/CustomFieldType.php b/lib/SP/Domain/CustomField/Models/CustomFieldType.php index 43a11f87..15f90177 100644 --- a/lib/SP/Domain/CustomField/Models/CustomFieldType.php +++ b/lib/SP/Domain/CustomField/Models/CustomFieldType.php @@ -24,13 +24,13 @@ namespace SP\Domain\CustomField\Models; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class CustomFieldType */ -class CustomFieldType extends Model implements DataModelInterface +class CustomFieldType extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; diff --git a/lib/SP/Domain/Install/Services/InstallerService.php b/lib/SP/Domain/Install/Services/InstallerService.php index f8978190..7c1d837c 100644 --- a/lib/SP/Domain/Install/Services/InstallerService.php +++ b/lib/SP/Domain/Install/Services/InstallerService.php @@ -29,7 +29,7 @@ use Exception; use SP\Core\Crypt\Hash; use SP\DataModel\ProfileData; use SP\DataModel\User; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; use SP\Domain\Config\Models\Config; use SP\Domain\Config\Ports\ConfigDataInterface; use SP\Domain\Config\Ports\ConfigFileService; @@ -344,7 +344,7 @@ final class InstallerService implements InstallerServiceInterface ] ); - $userProfile = new UserProfileData(['name' => 'Admin', 'profile' => new ProfileData()]); + $userProfile = new UserProfileItemWithIdAndName(['name' => 'Admin', 'profile' => new ProfileData()]); $userData = new User([ 'userGroupId' => $this->userGroupService->create($userGroup), diff --git a/lib/SP/Domain/Account/Models/ItemPreset.php b/lib/SP/Domain/ItemPreset/Models/ItemPreset.php similarity index 71% rename from lib/SP/Domain/Account/Models/ItemPreset.php rename to lib/SP/Domain/ItemPreset/Models/ItemPreset.php index c2625c27..08d1b840 100644 --- a/lib/SP/Domain/Account/Models/ItemPreset.php +++ b/lib/SP/Domain/ItemPreset/Models/ItemPreset.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -22,16 +22,27 @@ * along with sysPass. If not, see . */ -namespace SP\Domain\Account\Models; +namespace SP\Domain\ItemPreset\Models; -use SP\Domain\Common\Adapters\HydratableInterface; +use SP\DataModel\ItemPreset\AccountPermission; +use SP\DataModel\ItemPreset\AccountPrivate; +use SP\DataModel\ItemPreset\Password; +use SP\DataModel\ItemPreset\SessionTimeout; +use SP\Domain\Common\Attributes\Hydratable; +use SP\Domain\Common\Models\HydratableModel; use SP\Domain\Common\Models\Model; use SP\Domain\Common\Models\SerializedModel; /** * Class ItemPreset */ -class ItemPreset extends Model implements HydratableInterface +#[Hydratable('data', [ + Password::class, + AccountPrivate::class, + AccountPermission::class, + SessionTimeout::class +])] +class ItemPreset extends Model implements HydratableModel { use SerializedModel; @@ -69,16 +80,18 @@ class ItemPreset extends Model implements HydratableInterface return $this->data; } - public function getHash(): string - { - return sha1( - $this->type . (int)$this->userId . (int)$this->userGroupId . (int)$this->userProfileId . - (int)$this->priority - ); - } - public function getType(): ?string { return $this->type; } + + public function getId(): ?int + { + return $this->id; + } + + public function getUserId(): ?int + { + return $this->userId; + } } diff --git a/lib/SP/Domain/ItemPreset/Ports/ItemPresetRepository.php b/lib/SP/Domain/ItemPreset/Ports/ItemPresetRepository.php index e89b51ad..e2f6ff5d 100644 --- a/lib/SP/Domain/ItemPreset/Ports/ItemPresetRepository.php +++ b/lib/SP/Domain/ItemPreset/Ports/ItemPresetRepository.php @@ -24,27 +24,91 @@ namespace SP\Domain\ItemPreset\Ports; +use Exception; +use SP\DataModel\ItemSearchData; use SP\Domain\Common\Ports\Repository; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel; use SP\Infrastructure\Database\QueryResult; /** - * Class AccountDefaultPermissionRepository + * Class ItemPresetRepository * - * @package SP\Infrastructure\Account\Repositories + * @template T of ItemPresetModel */ interface ItemPresetRepository extends Repository { + /** + * Creates an item + * + * @throws ConstraintException + * @throws QueryException + */ + public function create(ItemPresetModel $itemPreset): QueryResult; + + /** + * Updates an item + * + * @throws ConstraintException + * @throws QueryException + */ + public function update(ItemPresetModel $itemPreset): int; + + /** + * Deletes an item + * + * @throws ConstraintException + * @throws QueryException + */ + public function delete(int $id): QueryResult; + /** * Returns the item for given id * - * @param string $type - * @param int $userId - * @param int $userGroupId - * @param int $userProfileId + * @param int $itemPresetId * * @return QueryResult + */ + public function getById(int $itemPresetId): QueryResult; + + /** + * Returns all the items + * + * @return QueryResult + */ + public function getAll(): QueryResult; + + /** + * Deletes all the items for given ids + * + * @throws ConstraintException + * @throws QueryException + */ + public function deleteByIdBatch(array $itemPresetIds): QueryResult; + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $itemSearchData + * + * @return QueryResult + * + * @throws ConstraintException + * @throws QueryException + * @throws Exception + */ + public function search(ItemSearchData $itemSearchData): QueryResult; + + /** + * Returns the item for given id + * + * @param string $type + * @param int $userId + * @param int $userGroupId + * @param int $userProfileId + * + * @return QueryResult * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Domain/ItemPreset/Ports/ItemPresetServiceInterface.php b/lib/SP/Domain/ItemPreset/Ports/ItemPresetService.php similarity index 80% rename from lib/SP/Domain/ItemPreset/Ports/ItemPresetServiceInterface.php rename to lib/SP/Domain/ItemPreset/Ports/ItemPresetService.php index 8d706b59..fa60f7cb 100644 --- a/lib/SP/Domain/ItemPreset/Ports/ItemPresetServiceInterface.php +++ b/lib/SP/Domain/ItemPreset/Ports/ItemPresetService.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,33 +25,31 @@ namespace SP\Domain\ItemPreset\Ports; use SP\DataModel\ItemSearchData; -use SP\Domain\Account\Models\ItemPreset; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\ItemPreset\Services\ItemPresetRequest; -use SP\Domain\ItemPreset\Services\ItemPresetService; +use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Infrastructure\Database\QueryResult; /** * Class ItemPresetService * - * @package SP\Domain\Account\Services + * @template T of ItemPresetModel */ -interface ItemPresetServiceInterface +interface ItemPresetService { /** * @throws ConstraintException * @throws QueryException */ - public function create(ItemPresetRequest $itemPresetRequest): int; + public function create(ItemPresetModel $itemPreset): int; /** * @throws ConstraintException * @throws QueryException */ - public function update(ItemPresetRequest $itemPresetRequest): int; + public function update(ItemPresetModel $itemPreset): int; /** * Deletes an item @@ -69,12 +67,12 @@ interface ItemPresetServiceInterface * @throws ConstraintException * @throws QueryException */ - public function getById(int $id): ItemPreset; + public function getById(int $id): ItemPresetModel; /** * Returns all the items * - * @return ItemPreset[] + * @return array * @throws ConstraintException * @throws QueryException */ @@ -83,6 +81,7 @@ interface ItemPresetServiceInterface /** * Searches for items by a given filter * + * @return QueryResult * @throws ConstraintException * @throws QueryException */ @@ -92,16 +91,16 @@ interface ItemPresetServiceInterface * @throws ConstraintException * @throws QueryException */ - public function getForCurrentUser(string $type): ?ItemPreset; + public function getForCurrentUser(string $type): ?ItemPresetModel; /** * @throws ConstraintException * @throws QueryException */ - public function getForUser(string $type, int $userId, int $userGroupId, int $userProfileId): ?ItemPreset; + public function getForUser(string $type, int $userId, int $userGroupId, int $userProfileId): ?ItemPresetModel; /** - * @param int[] $ids + * @param int[] $ids * * @throws ConstraintException * @throws QueryException diff --git a/lib/SP/Domain/ItemPreset/Services/ItemPresetService.php b/lib/SP/Domain/ItemPreset/Services/ItemPreset.php similarity index 64% rename from lib/SP/Domain/ItemPreset/Services/ItemPresetService.php rename to lib/SP/Domain/ItemPreset/Services/ItemPreset.php index 9928a6d2..e61d8e80 100644 --- a/lib/SP/Domain/ItemPreset/Services/ItemPresetService.php +++ b/lib/SP/Domain/ItemPreset/Services/ItemPreset.php @@ -26,50 +26,47 @@ namespace SP\Domain\ItemPreset\Services; use SP\Core\Application; use SP\DataModel\ItemSearchData; -use SP\Domain\Account\Models\ItemPreset; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\Core\Exceptions\SPException; +use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel; use SP\Domain\ItemPreset\Ports\ItemPresetRepository; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Infrastructure\Database\QueryResult; -use SP\Infrastructure\ItemPreset\Repositories\ItemPresetBaseRepository; + +use function SP\__u; /** - * Class ItemPresetService + * Class ItemPreset * - * @package SP\Domain\Account\Services + * @template T of ItemPresetModel */ -final class ItemPresetService extends Service implements ItemPresetServiceInterface +final class ItemPreset extends Service implements ItemPresetService { - private ItemPresetBaseRepository $itemPresetRepository; - public function __construct(Application $application, ItemPresetRepository $itemPresetRepository) + public function __construct(Application $application, private readonly ItemPresetRepository $itemPresetRepository) { parent::__construct($application); - - $this->itemPresetRepository = $itemPresetRepository; } /** * @throws ConstraintException * @throws QueryException */ - public function create(ItemPresetRequest $itemPresetRequest): int + public function create(ItemPresetModel $itemPreset): int { - return $this->itemPresetRepository->create($itemPresetRequest->prepareToPersist()); + return $this->itemPresetRepository->create($itemPreset)->getLastId(); } /** * @throws ConstraintException * @throws QueryException */ - public function update(ItemPresetRequest $itemPresetRequest): int + public function update(ItemPresetModel $itemPreset): int { - return $this->itemPresetRepository->update($itemPresetRequest->prepareToPersist()); + return $this->itemPresetRepository->update($itemPreset); } /** @@ -81,8 +78,8 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf */ public function delete(int $id): ItemPresetService { - if ($this->itemPresetRepository->delete($id) === 0) { - throw new NoSuchItemException(__u('Value not found')); + if ($this->itemPresetRepository->delete($id)->getAffectedNumRows() === 0) { + throw NoSuchItemException::error(__u('Value not found')); } return $this; @@ -91,36 +88,35 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf /** * Returns the item for given id * + * @param int $id + * @return ItemPresetModel * @throws NoSuchItemException - * @throws ConstraintException - * @throws QueryException */ - public function getById(int $id): ItemPreset + public function getById(int $id): ItemPresetModel { $result = $this->itemPresetRepository->getById($id); if ($result->getNumRows() === 0) { - throw new NoSuchItemException(__u('Value not found')); + throw NoSuchItemException::error(__u('Value not found')); } - return $result->getData(); + return $result->getData(ItemPresetModel::class); } /** * Returns all the items * - * @return ItemPreset[] - * @throws ConstraintException - * @throws QueryException + * @return array */ public function getAll(): array { - return $this->itemPresetRepository->getAll()->getDataAsArray(); + return $this->itemPresetRepository->getAll()->getDataAsArray(ItemPresetModel::class); } /** * Searches for items by a given filter * + * @return QueryResult * @throws ConstraintException * @throws QueryException */ @@ -133,7 +129,7 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf * @throws ConstraintException * @throws QueryException */ - public function getForCurrentUser(string $type): ?ItemPreset + public function getForCurrentUser(string $type): ?ItemPresetModel { $userData = $this->context->getUserData(); @@ -149,28 +145,18 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf * @throws ConstraintException * @throws QueryException */ - public function getForUser( - string $type, - int $userId, - int $userGroupId, - int $userProfileId - ): ?ItemPreset { - $result = $this->itemPresetRepository->getByFilter( + public function getForUser(string $type, int $userId, int $userGroupId, int $userProfileId): ?ItemPresetModel + { + return $this->itemPresetRepository->getByFilter( $type, $userId, $userGroupId, $userProfileId - ); - - if ($result->getNumRows() === 1) { - return $result->getData(); - } - - return null; + )->getData(ItemPresetModel::class); } /** - * @param int[] $ids + * @param int[] $ids * * @throws ConstraintException * @throws QueryException @@ -178,13 +164,10 @@ final class ItemPresetService extends Service implements ItemPresetServiceInterf */ public function deleteByIdBatch(array $ids): int { - $count = $this->itemPresetRepository->deleteByIdBatch($ids); + $count = $this->itemPresetRepository->deleteByIdBatch($ids)->getAffectedNumRows(); if ($count !== count($ids)) { - throw new ServiceException( - __u('Error while deleting the values'), - SPException::WARNING - ); + throw ServiceException::warning(__u('Error while deleting the values')); } return $count; diff --git a/lib/SP/Domain/ItemPreset/Services/ItemPresetRequest.php b/lib/SP/Domain/ItemPreset/Services/ItemPresetRequest.php deleted file mode 100644 index ddf0de2f..00000000 --- a/lib/SP/Domain/ItemPreset/Services/ItemPresetRequest.php +++ /dev/null @@ -1,67 +0,0 @@ -. - */ - -namespace SP\Domain\ItemPreset\Services; - -use SP\Domain\Account\Models\ItemPreset; - -/** - * Class ItemPresetRequest - * - * @package SP\Domain\ItemPreset\Services - */ -final class ItemPresetRequest -{ - private ItemPreset $itemPresetData; - private $data; - - /** - * ItemPresetRequest constructor. - */ - public function __construct(ItemPreset $itemPresetData, $data) - { - $this->itemPresetData = $itemPresetData; - $this->data = $data; - } - - public function getItemPresetData(): ItemPreset - { - return $this->itemPresetData; - } - - /** - * @return mixed - */ - public function getData() - { - return $this->data; - } - - public function prepareToPersist(): ItemPreset - { - $this->itemPresetData->setData(serialize($this->data)); - - return $this->itemPresetData; - } -} diff --git a/lib/SP/Domain/Notification/Ports/NotificationServiceInterface.php b/lib/SP/Domain/Notification/Ports/NotificationServiceInterface.php index 9e9d9e24..2a81e4ce 100644 --- a/lib/SP/Domain/Notification/Ports/NotificationServiceInterface.php +++ b/lib/SP/Domain/Notification/Ports/NotificationServiceInterface.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Domain\Notification\Ports; use SP\DataModel\ItemSearchData; -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -45,7 +45,7 @@ interface NotificationServiceInterface * @throws ConstraintException * @throws QueryException */ - public function create(NotificationData $itemData): int; + public function create(NotificationItemWithIdAndName $itemData): int; /** * Updates an item @@ -53,14 +53,14 @@ interface NotificationServiceInterface * @throws ConstraintException * @throws QueryException */ - public function update(NotificationData $itemData): int; + public function update(NotificationItemWithIdAndName $itemData): int; /** * Devolver los elementos con los ids especificados * * @param int[] $ids * - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ @@ -113,12 +113,12 @@ interface NotificationServiceInterface * @throws QueryException * @throws NoSuchItemException */ - public function getById(int $id): NotificationData; + public function getById(int $id): NotificationItemWithIdAndName; /** * Returns all the items * - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ @@ -136,21 +136,21 @@ interface NotificationServiceInterface /** * Devolver las notificaciones de un usuario para una fecha y componente determinados * - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ public function getForUserIdByDate(string $component, int $id): array; /** - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ public function getAllForUserId(int $id): array; /** - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Domain/Notification/Services/NotificationService.php b/lib/SP/Domain/Notification/Services/NotificationService.php index f916c5e4..e4ce4e4a 100644 --- a/lib/SP/Domain/Notification/Services/NotificationService.php +++ b/lib/SP/Domain/Notification/Services/NotificationService.php @@ -26,7 +26,7 @@ namespace SP\Domain\Notification\Services; use SP\Core\Application; use SP\DataModel\ItemSearchData; -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; @@ -60,7 +60,7 @@ final class NotificationService extends Service implements NotificationServiceIn * @throws ConstraintException * @throws QueryException */ - public function create(NotificationData $itemData): int + public function create(NotificationItemWithIdAndName $itemData): int { return $this->notificationRepository->create($itemData)->getLastId(); } @@ -71,7 +71,7 @@ final class NotificationService extends Service implements NotificationServiceIn * @throws ConstraintException * @throws QueryException */ - public function update(NotificationData $itemData): int + public function update(NotificationItemWithIdAndName $itemData): int { return $this->notificationRepository->update($itemData); } @@ -81,7 +81,7 @@ final class NotificationService extends Service implements NotificationServiceIn * * @param int[] $ids * - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ @@ -175,7 +175,7 @@ final class NotificationService extends Service implements NotificationServiceIn * @throws QueryException * @throws NoSuchItemException */ - public function getById(int $id): NotificationData + public function getById(int $id): NotificationItemWithIdAndName { $result = $this->notificationRepository->getById($id); @@ -189,7 +189,7 @@ final class NotificationService extends Service implements NotificationServiceIn /** * Returns all the items * - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ @@ -215,7 +215,7 @@ final class NotificationService extends Service implements NotificationServiceIn /** * Devolver las notificaciones de un usuario para una fecha y componente determinados * - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ @@ -225,7 +225,7 @@ final class NotificationService extends Service implements NotificationServiceIn } /** - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ @@ -235,7 +235,7 @@ final class NotificationService extends Service implements NotificationServiceIn } /** - * @return NotificationData[] + * @return NotificationItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Domain/Plugin/Ports/PluginManagerInterface.php b/lib/SP/Domain/Plugin/Ports/PluginManagerInterface.php index 988e457a..54a0a760 100644 --- a/lib/SP/Domain/Plugin/Ports/PluginManagerInterface.php +++ b/lib/SP/Domain/Plugin/Ports/PluginManagerInterface.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,7 +24,7 @@ namespace SP\Domain\Plugin\Ports; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -169,7 +169,7 @@ interface PluginManagerInterface /** * Devolver los plugins activados * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Domain/Plugin/Services/PluginManager.php b/lib/SP/Domain/Plugin/Services/PluginManager.php index df8c46ed..b15b5eeb 100644 --- a/lib/SP/Domain/Plugin/Services/PluginManager.php +++ b/lib/SP/Domain/Plugin/Services/PluginManager.php @@ -25,7 +25,7 @@ namespace SP\Domain\Plugin\Services; use SP\Core\Application; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; @@ -264,7 +264,7 @@ final class PluginManager extends Service implements PluginManagerInterface /** * Devolver los plugins activados * - * @return ItemData[] + * @return ItemItemWithIdAndName[] * @throws ConstraintException * @throws QueryException * @throws SPException diff --git a/lib/SP/Domain/Tag/Models/Tag.php b/lib/SP/Domain/Tag/Models/Tag.php index 1e87b570..2947841c 100644 --- a/lib/SP/Domain/Tag/Models/Tag.php +++ b/lib/SP/Domain/Tag/Models/Tag.php @@ -24,13 +24,13 @@ namespace SP\Domain\Tag\Models; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class Tag */ -class Tag extends Model implements DataModelInterface +class Tag extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; diff --git a/lib/SP/Domain/User/Models/UserGroup.php b/lib/SP/Domain/User/Models/UserGroup.php index 255e620c..3d150484 100644 --- a/lib/SP/Domain/User/Models/UserGroup.php +++ b/lib/SP/Domain/User/Models/UserGroup.php @@ -24,13 +24,13 @@ namespace SP\Domain\User\Models; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class GroupData */ -class UserGroup extends Model implements DataModelInterface +class UserGroup extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; diff --git a/lib/SP/Domain/User/Ports/UserProfileServiceInterface.php b/lib/SP/Domain/User/Ports/UserProfileServiceInterface.php index c6f48ce2..0ea72488 100644 --- a/lib/SP/Domain/User/Ports/UserProfileServiceInterface.php +++ b/lib/SP/Domain/User/Ports/UserProfileServiceInterface.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Domain\User\Ports; use SP\DataModel\ItemSearchData; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -45,7 +45,7 @@ interface UserProfileServiceInterface * @throws QueryException * @throws NoSuchItemException */ - public function getById(int $id): UserProfileData; + public function getById(int $id): UserProfileItemWithIdAndName; /** * @throws ConstraintException @@ -74,7 +74,7 @@ interface UserProfileServiceInterface * @throws QueryException * @throws DuplicatedItemException */ - public function create(UserProfileData $itemData): int; + public function create(UserProfileItemWithIdAndName $itemData): int; /** * @throws ConstraintException @@ -82,7 +82,7 @@ interface UserProfileServiceInterface * @throws DuplicatedItemException * @throws ServiceException */ - public function update(UserProfileData $itemData): void; + public function update(UserProfileItemWithIdAndName $itemData): void; /** * @throws ConstraintException @@ -93,7 +93,7 @@ interface UserProfileServiceInterface /** * Get all items from the service's repository * - * @return UserProfileData[] + * @return UserProfileItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Domain/User/Services/UserProfileService.php b/lib/SP/Domain/User/Services/UserProfileService.php index ffa099c1..e0ebb3c7 100644 --- a/lib/SP/Domain/User/Services/UserProfileService.php +++ b/lib/SP/Domain/User/Services/UserProfileService.php @@ -27,7 +27,7 @@ namespace SP\Domain\User\Services; use SP\Core\Application; use SP\DataModel\ItemSearchData; use SP\DataModel\ProfileData; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Common\Services\ServiceItemTrait; @@ -67,7 +67,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte * @throws QueryException * @throws NoSuchItemException */ - public function getById(int $id): UserProfileData + public function getById(int $id): UserProfileItemWithIdAndName { $result = $this->userProfileRepository->getById($id); @@ -130,7 +130,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte * @throws QueryException * @throws DuplicatedItemException */ - public function create(UserProfileData $itemData): int + public function create(UserProfileItemWithIdAndName $itemData): int { return $this->userProfileRepository->create($itemData); } @@ -141,7 +141,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte * @throws DuplicatedItemException * @throws ServiceException */ - public function update(UserProfileData $itemData): void + public function update(UserProfileItemWithIdAndName $itemData): void { $update = $this->userProfileRepository->update($itemData); @@ -163,7 +163,7 @@ final class UserProfileService extends Service implements UserProfileServiceInte /** * Get all items from the service's repository * - * @return UserProfileData[] + * @return UserProfileItemWithIdAndName[] * @throws ConstraintException * @throws QueryException */ diff --git a/lib/SP/Infrastructure/Account/Repositories/AccountFile.php b/lib/SP/Infrastructure/Account/Repositories/AccountFile.php index c6808b66..86b3ebe5 100644 --- a/lib/SP/Infrastructure/Account/Repositories/AccountFile.php +++ b/lib/SP/Infrastructure/Account/Repositories/AccountFile.php @@ -24,7 +24,7 @@ namespace SP\Infrastructure\Account\Repositories; -use SP\DataModel\FileData; +use SP\DataModel\FileItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Account\Ports\AccountFileRepository; use SP\Domain\Core\Exceptions\ConstraintException; @@ -48,13 +48,13 @@ final class AccountFile extends BaseRepository implements AccountFileRepository /** * Creates an item * - * @param FileData $fileData + * @param FileItemWithIdAndName $fileData * * @return int * @throws ConstraintException * @throws QueryException */ - public function create(FileData $fileData): int + public function create(FileItemWithIdAndName $fileData): int { $query = $this->queryFactory ->newInsert() diff --git a/lib/SP/Infrastructure/Account/Repositories/AccountToUser.php b/lib/SP/Infrastructure/Account/Repositories/AccountToUser.php index 93c1fefd..45e23280 100644 --- a/lib/SP/Infrastructure/Account/Repositories/AccountToUser.php +++ b/lib/SP/Infrastructure/Account/Repositories/AccountToUser.php @@ -24,7 +24,7 @@ namespace SP\Infrastructure\Account\Repositories; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToUserRepository; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -150,6 +150,6 @@ final class AccountToUser extends BaseRepository implements AccountToUserReposit ->bindValues(['accountId' => $id]) ->orderBy(['User.name ASC']); - return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemData::class)); + return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemItemWithIdAndName::class)); } } diff --git a/lib/SP/Infrastructure/Account/Repositories/AccountToUserGroup.php b/lib/SP/Infrastructure/Account/Repositories/AccountToUserGroup.php index c52016ed..be8f3ac3 100644 --- a/lib/SP/Infrastructure/Account/Repositories/AccountToUserGroup.php +++ b/lib/SP/Infrastructure/Account/Repositories/AccountToUserGroup.php @@ -24,7 +24,7 @@ namespace SP\Infrastructure\Account\Repositories; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToUserGroupRepository; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -67,7 +67,7 @@ final class AccountToUserGroup extends BaseRepository implements AccountToUserGr ->bindValues(['accountId' => $id]) ->orderBy(['UserGroup.name ASC']); - return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemData::class)); + return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemItemWithIdAndName::class)); } /** @@ -92,7 +92,7 @@ final class AccountToUserGroup extends BaseRepository implements AccountToUserGr ->bindValues(['userGroupId' => $id]) ->orderBy(['UserGroup.name ASC']); - return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemData::class)); + return $this->db->doSelect(QueryData::build($query)->setMapClassName(ItemItemWithIdAndName::class)); } /** diff --git a/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php b/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php new file mode 100644 index 00000000..ef682bef --- /dev/null +++ b/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php @@ -0,0 +1,273 @@ +. + */ + +namespace SP\Infrastructure\ItemPreset\Repositories; + +use Exception; +use SP\DataModel\ItemSearchData; +use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel; +use SP\Domain\ItemPreset\Ports\ItemPresetRepository; +use SP\Infrastructure\Common\Repositories\BaseRepository; +use SP\Infrastructure\Common\Repositories\RepositoryItemTrait; +use SP\Infrastructure\Database\QueryData; +use SP\Infrastructure\Database\QueryResult; + +use function SP\__u; + +/** + * Class ItemPresetBaseRepository + * + * @template T of ItemPresetModel + */ +class ItemPreset extends BaseRepository implements ItemPresetRepository +{ + use RepositoryItemTrait; + + public const TABLE = 'ItemPreset'; + + /** + * Creates an item + * + * @throws ConstraintException + * @throws QueryException + */ + public function create(ItemPresetModel $itemPreset): QueryResult + { + $query = $this->queryFactory + ->newInsert() + ->into(self::TABLE) + ->cols($itemPreset->toArray(null, ['id'])); + + $queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while creating the permission')); + + return $this->db->doQuery($queryData); + } + + /** + * Updates an item + * + * @throws ConstraintException + * @throws QueryException + */ + public function update(ItemPresetModel $itemPreset): int + { + $query = $this->queryFactory + ->newUpdate() + ->table(self::TABLE) + ->cols($itemPreset->toArray(null, ['id'])) + ->where('id = :id') + ->limit(1) + ->bindValues( + [ + 'id' => $itemPreset->getId() + ] + ); + + $queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while updating the permission')); + + return $this->db->doQuery($queryData)->getAffectedNumRows(); + } + + /** + * Deletes an item + * + * @throws ConstraintException + * @throws QueryException + */ + public function delete(int $id): QueryResult + { + $query = $this->queryFactory + ->newDelete() + ->from(self::TABLE) + ->where('id = :id') + ->bindValues(['id' => $id]); + + $queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while deleting the permission')); + + return $this->db->doQuery($queryData); + } + + /** + * Returns the item for given id + * + * @param int $itemPresetId + * + * @return QueryResult + */ + public function getById(int $itemPresetId): QueryResult + { + $query = $this->queryFactory + ->newSelect() + ->from(self::TABLE) + ->cols(ItemPresetModel::getCols()) + ->where('id = :id') + ->bindValues(['id' => $itemPresetId]) + ->limit(1); + + $queryData = QueryData::buildWithMapper($query, ItemPresetModel::class); + + return $this->db->doSelect($queryData); + } + + /** + * Returns the item for given id + * + * @param string $type + * @param int $userId + * @param int $userGroupId + * @param int $userProfileId + * + * @return QueryResult + */ + public function getByFilter(string $type, int $userId, int $userGroupId, int $userProfileId): QueryResult + { + $query = $this->queryFactory + ->newSelect() + ->from(self::TABLE) + ->cols(ItemPresetModel::getCols()) + ->cols( + [ + 'IF(userId IS NOT NULL, priority + 3, + IF(userGroupId IS NOT NULL, priority + 2, + IF(userProfileId IS NOT NULL, priority + 1, 0)))' => 'score' + ] + ) + ->where('type = :type') + ->where( + '(userId = :userId OR userGroupId = :userGroupId OR userProfileId = :userProfileId + OR userGroupId IN (SELECT UserToUserGroup.userGroupId + FROM UserToUserGroup + WHERE UserToUserGroup.userId = :userId))' + ) + ->bindValues([ + 'type' => $type, + 'userId' => $userId, + 'userGroupId' => $userGroupId, + 'userProfileId' => $userProfileId + ]) + ->orderBy(['score DESC']) + ->limit(1); + + $queryData = QueryData::buildWithMapper($query, ItemPresetModel::class); + + return $this->db->doSelect($queryData); + } + + /** + * Returns all the items + * + * @return QueryResult + */ + public function getAll(): QueryResult + { + $query = $this->queryFactory + ->newSelect() + ->from(self::TABLE) + ->cols(ItemPresetModel::getCols()); + + return $this->db->doSelect(QueryData::buildWithMapper($query, ItemPresetModel::class)); + } + + /** + * Deletes all the items for given ids + * + * @throws ConstraintException + * @throws QueryException + */ + public function deleteByIdBatch(array $itemPresetIds): QueryResult + { + if (count($itemPresetIds) === 0) { + return new QueryResult(); + } + + $query = $this->queryFactory + ->newDelete() + ->from(self::TABLE) + ->where('id IN (:ids)', ['ids' => $itemPresetIds]); + + $queryData = QueryData::build($query)->setOnErrorMessage(__u('Error while removing the permissions')); + + return $this->db->doQuery($queryData); + } + + + /** + * Searches for items by a given filter + * + * @param ItemSearchData $itemSearchData + * + * @return QueryResult + * + * @throws ConstraintException + * @throws QueryException + * @throws Exception + */ + public function search(ItemSearchData $itemSearchData): QueryResult + { + $query = $this->queryFactory + ->newSelect() + ->from(self::TABLE) + ->cols(ItemPresetModel::getColsWithPreffix('ItemPreset')) + ->cols([ + 'IF(userId IS NOT NULL, priority + 3, + IF(userGroupId IS NOT NULL, priority + 2, + IF(userProfileId IS NOT NULL, priority + 1, 0)))' => 'score', + 'User.name' => 'userName', + 'UserProfile.name' => 'userProfileName', + 'UserGroup.name' => 'userGroupName' + ]) + ->leftJoin('User', 'ItemPreset.userId = User.id ') + ->leftJoin('UserProfile', 'ItemPreset.userProfileId = UserProfile.id') + ->leftJoin('UserGroup', 'ItemPreset.userGroupId = UserGroup.id') + ->orderBy(['ItemPreset.type', 'score DESC']) + ->limit($itemSearchData->getLimitCount()) + ->offset($itemSearchData->getLimitStart()); + + if (!empty($itemSearchData->getSeachString())) { + $query->where( + 'ItemPreset.type LIKE :type + OR User.name LIKE :userName + OR UserProfile.name LIKE :userProfileName + OR UserGroup.name LIKE :userGroupName' + ); + + $search = '%' . $itemSearchData->getSeachString() . '%'; + + $query->bindValues( + [ + 'type' => $search, + 'userName' => $search, + 'userProfileName' => $search, + 'userGroupName' => $search + ] + ); + } + + $queryData = QueryData::build($query)->setMapClassName(ItemPresetModel::class); + + return $this->db->doSelect($queryData, true); + } +} diff --git a/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPresetBaseRepository.php b/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPresetBaseRepository.php deleted file mode 100644 index 868926f5..00000000 --- a/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPresetBaseRepository.php +++ /dev/null @@ -1,369 +0,0 @@ -. - */ - -namespace SP\Infrastructure\ItemPreset\Repositories; - -use RuntimeException; -use SP\DataModel\ItemSearchData; -use SP\Domain\Account\Models\ItemPreset; -use SP\Domain\Common\Ports\Repository; -use SP\Domain\Core\Exceptions\ConstraintException; -use SP\Domain\Core\Exceptions\QueryException; -use SP\Domain\ItemPreset\Ports\ItemPresetRepository; -use SP\Infrastructure\Common\Repositories\BaseRepository; -use SP\Infrastructure\Common\Repositories\RepositoryItemTrait; -use SP\Infrastructure\Database\QueryData; -use SP\Infrastructure\Database\QueryResult; - -/** - * Class AccountDefaultPermissionRepository - * - * @package SP\Infrastructure\Account\Repositories - */ -class ItemPresetBaseRepository extends BaseRepository implements Repository, ItemPresetRepository -{ - use RepositoryItemTrait; - - /** - * Creates an item - * - * @param ItemPreset $itemData - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function create($itemData): int - { - $queryData = new QueryData(); - $queryData->setQuery( - 'INSERT INTO ItemPreset - SET type = ?, - userId = ?, - userGroupId = ?, - userProfileId = ?, - `fixed` = ?, - priority = ?, - `data` = ?, - `hash` = ?' - ); - $queryData->setParams([ - $itemData->getType(), - $itemData->getUserId(), - $itemData->getUserGroupId(), - $itemData->getUserProfileId(), - $itemData->getFixed(), - $itemData->getPriority(), - $itemData->getData(), - $itemData->getHash(), - ]); - $queryData->setOnErrorMessage(__u('Error while creating the permission')); - - return $this->db->doQuery($queryData)->getLastId(); - } - - /** - * Updates an item - * - * @param ItemPreset $itemData - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function update($itemData): int - { - $queryData = new QueryData(); - $queryData->setQuery( - 'UPDATE ItemPreset - SET type = ?, - userId = ?, - userGroupId = ?, - userProfileId = ?, - `fixed` = ?, - priority = ?, - `data` = ?, - `hash` = ? - WHERE id = ? LIMIT 1' - ); - $queryData->setParams([ - $itemData->getType(), - $itemData->getUserId(), - $itemData->getUserGroupId(), - $itemData->getUserProfileId(), - $itemData->getFixed(), - $itemData->getPriority(), - $itemData->getData(), - $itemData->getHash(), - $itemData->getId(), - ]); - $queryData->setOnErrorMessage(__u('Error while updating the permission')); - - return $this->db->doQuery($queryData)->getAffectedNumRows(); - } - - /** - * Deletes an item - * - * @param int $id - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function delete(int $id): int - { - $queryData = new QueryData(); - $queryData->setQuery('DELETE FROM ItemPreset WHERE id = ? LIMIT 1'); - $queryData->setParams([$id]); - $queryData->setOnErrorMessage(__u('Error while removing the permission')); - - return $this->db->doQuery($queryData)->getAffectedNumRows(); - } - - /** - * Returns the item for given id - * - * @param int $id - * - * @return QueryResult - * @throws ConstraintException - * @throws QueryException - */ - public function getById(int $id): QueryResult - { - $queryData = new QueryData(); - $queryData->setMapClassName(ItemPreset::class); - $queryData->setQuery( - 'SELECT id, type, userId, userGroupId, userProfileId, `fixed`, priority, `data` - FROM ItemPreset WHERE id = ? LIMIT 1' - ); - $queryData->setParams([$id]); - - return $this->db->doSelect($queryData); - } - - /** - * Returns the item for given id - * - * @param string $type - * @param int $userId - * @param int $userGroupId - * @param int $userProfileId - * - * @return QueryResult - * @throws ConstraintException - * @throws QueryException - */ - public function getByFilter( - string $type, - int $userId, - int $userGroupId, - int $userProfileId - ): QueryResult { - $queryData = new QueryData(); - $queryData->setMapClassName(ItemPreset::class); - $queryData->setQuery( - 'SELECT id, type, userId, userGroupId, userProfileId, `fixed`, priority, `data`, - IF(userId IS NOT NULL, priority + 3, - IF(userGroupId IS NOT NULL, priority + 2, - IF(userProfileId IS NOT NULL, priority + 1, 0))) AS score - FROM ItemPreset - WHERE type = ? - AND (userId = ? - OR userGroupId = ? - OR userProfileId = ? - OR userGroupId IN (SELECT UserToUserGroup.userGroupId - FROM UserToUserGroup - WHERE UserToUserGroup.userId = ?) - ) - ORDER BY score DESC - LIMIT 1' - ); - - $queryData->setParams([$type, $userId, $userGroupId, $userProfileId, $userId]); - - return $this->db->doSelect($queryData); - } - - /** - * Returns all the items - * - * @return QueryResult - * @throws ConstraintException - * @throws QueryException - */ - public function getAll(): QueryResult - { - $queryData = new QueryData(); - $queryData->setMapClassName(ItemPreset::class); - $queryData->setQuery( - 'SELECT id, type, userId, userGroupId, userProfileId, `fixed`, priority, `data` - FROM ItemPreset' - ); - - return $this->db->doSelect($queryData); - } - - /** - * Returns all the items for given ids - * - * @param array $ids - * - * @return QueryResult - * @throws ConstraintException - * @throws QueryException - */ - public function getByIdBatch(array $ids): QueryResult - { - if (count($ids) === 0) { - return new QueryResult(); - } - - $queryData = new QueryData(); - $queryData->setMapClassName(ItemPreset::class); - $queryData->setQuery( - 'SELECT type, userId, userGroupId, userProfileId, `fixed`, priority, `data` - FROM ItemPreset WHERE id IN ('.$this->buildParamsFromArray($ids).')' - ); - $queryData->setParams($ids); - - return $this->db->doSelect($queryData); - } - - /** - * Deletes all the items for given ids - * - * @param int[] $ids - * - * @return int - * @throws ConstraintException - * @throws QueryException - */ - public function deleteByIdBatch(array $ids): int - { - if (count($ids) === 0) { - return 0; - } - - $queryData = new QueryData(); - $queryData->setQuery('DELETE FROM ItemPreset WHERE id IN ('.$this->buildParamsFromArray($ids).')'); - $queryData->setParams($ids); - $queryData->setOnErrorMessage(__u('Error while removing the permissions')); - - return $this->db->doQuery($queryData)->getAffectedNumRows(); - } - - /** - * Checks whether the item is in use or not - * - * @param $id int - */ - public function checkInUse(int $id): bool - { - throw new RuntimeException('Not implemented'); - } - - /** - * Checks whether the item is duplicated on updating - * - * @param mixed $itemData - */ - public function checkDuplicatedOnUpdate($itemData): bool - { - throw new RuntimeException('Not implemented'); - } - - /** - * Checks whether the item is duplicated on adding - * - * @param mixed $itemData - */ - public function checkDuplicatedOnAdd($itemData): bool - { - throw new RuntimeException('Not implemented'); - } - - /** - * Searches for items by a given filter - * - * @param ItemSearchData $itemSearchData - * - * @return QueryResult - * @throws ConstraintException - * @throws QueryException - */ - public function search(ItemSearchData $itemSearchData): QueryResult - { - $queryData = new QueryData(); - $queryData->setSelect( - 'ItemPreset.id, - ItemPreset.type, - ItemPreset.userId, - ItemPreset.userGroupId, - ItemPreset.userProfileId, - ItemPreset.`fixed`, - ItemPreset.priority, - ItemPreset.data, - User.name AS userName, - UserProfile.name AS userProfileName, - UserGroup.name AS userGroupName, - IF(ItemPreset.userId IS NOT NULL, ItemPreset.priority + 3, - IF(ItemPreset.userGroupId IS NOT NULL, ItemPreset.priority + 2, - IF(ItemPreset.userProfileId IS NOT NULL, ItemPreset.priority + 1, 0))) AS score' - ); - $queryData->setFrom( - ' - ItemPreset - LEFT JOIN User ON ItemPreset.userId = User.id - LEFT JOIN UserProfile ON ItemPreset.userProfileId = UserProfile.id - LEFT JOIN UserGroup ON ItemPreset.userGroupId = UserGroup.id' - ); - $queryData->setOrder( - 'ItemPreset.type, score DESC' - ); - - if (!empty($itemSearchData->getSeachString())) { - $queryData->setWhere( - 'ItemPreset.type LIKE ? - OR User.name LIKE ? - OR UserProfile.name LIKE ? - OR UserGroup.name LIKE ?' - ); - - $search = '%'.$itemSearchData->getSeachString().'%'; - $queryData->addParam($search); - $queryData->addParam($search); - $queryData->addParam($search); - $queryData->addParam($search); - } - - $queryData->setLimit( - '?,?', - [$itemSearchData->getLimitStart(), $itemSearchData->getLimitCount()] - ); - - return $this->db->doSelect($queryData, true); - } -} diff --git a/lib/SP/Infrastructure/Notification/Repositories/NotificationBaseRepository.php b/lib/SP/Infrastructure/Notification/Repositories/NotificationBaseRepository.php index 585ffb7e..b4a3143e 100644 --- a/lib/SP/Infrastructure/Notification/Repositories/NotificationBaseRepository.php +++ b/lib/SP/Infrastructure/Notification/Repositories/NotificationBaseRepository.php @@ -26,7 +26,7 @@ namespace SP\Infrastructure\Notification\Repositories; use RuntimeException; use SP\DataModel\ItemSearchData; -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Notification\Ports\NotificationRepository; @@ -48,7 +48,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific /** * Creates an item * - * @param NotificationData $itemData + * @param NotificationItemWithIdAndName $itemData * * @return QueryResult * @throws ConstraintException @@ -85,7 +85,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific /** * Updates an item * - * @param NotificationData $itemData + * @param NotificationItemWithIdAndName $itemData * * @return int * @throws ConstraintException @@ -208,7 +208,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific WHERE id = ? LIMIT 1'; $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setQuery($query); $queryData->addParam($id); $queryData->setOnErrorMessage(__u('Error while retrieving notification')); @@ -239,7 +239,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific ORDER BY id'; $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setQuery($query); $queryData->setOnErrorMessage(__u('Error while retrieving the notifications')); @@ -276,7 +276,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific ORDER BY id'; $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setQuery($query); $queryData->setParams($ids); @@ -350,7 +350,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific public function search(ItemSearchData $itemSearchData): QueryResult { $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setSelect('id, type, component, description, `date`, checked, userId, sticky, onlyAdmin'); $queryData->setFrom('Notification'); $queryData->setOrder('`date` DESC'); @@ -387,7 +387,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific int $userId ): QueryResult { $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setSelect('id, type, component, description, `date`, checked, userId, sticky, onlyAdmin'); $queryData->setFrom('Notification'); $queryData->setOrder('`date` DESC'); @@ -434,7 +434,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific int $userId ): QueryResult { $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setSelect('id, type, component, description, `date`, checked, userId, sticky, onlyAdmin'); $queryData->setFrom('Notification'); $queryData->setOrder('`date` DESC'); @@ -518,7 +518,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific ORDER BY id'; $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setQuery($query); $queryData->setParams([$component, $userId]); $queryData->setOnErrorMessage(__u('Error while retrieving the notifications')); @@ -551,7 +551,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific ORDER BY `date` DESC '; $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setQuery($query); $queryData->addParam($id); $queryData->setOnErrorMessage(__u('Error while retrieving the notifications')); @@ -585,7 +585,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific ORDER BY `date` DESC '; $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setQuery($query); $queryData->addParam($id); $queryData->setOnErrorMessage(__u('Error while retrieving the notifications')); @@ -618,7 +618,7 @@ final class NotificationBaseRepository extends BaseRepository implements Notific ORDER BY `date` DESC '; $queryData = new QueryData(); - $queryData->setMapClassName(NotificationData::class); + $queryData->setMapClassName(NotificationItemWithIdAndName::class); $queryData->setQuery($query); $queryData->addParam($id); $queryData->setOnErrorMessage(__u('Error while retrieving the notifications')); diff --git a/lib/SP/Infrastructure/Plugin/Repositories/PluginBaseRepository.php b/lib/SP/Infrastructure/Plugin/Repositories/PluginBaseRepository.php index f760d739..d81c5808 100644 --- a/lib/SP/Infrastructure/Plugin/Repositories/PluginBaseRepository.php +++ b/lib/SP/Infrastructure/Plugin/Repositories/PluginBaseRepository.php @@ -25,7 +25,7 @@ namespace SP\Infrastructure\Plugin\Repositories; use RuntimeException; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -82,7 +82,7 @@ final class PluginBaseRepository extends BaseRepository implements PluginReposit public function getEnabled(): QueryResult { $queryData = new QueryData(); - $queryData->setMapClassName(ItemData::class); + $queryData->setMapClassName(ItemItemWithIdAndName::class); $queryData->setQuery('SELECT id, `name` FROM Plugin WHERE enabled = 1 ORDER BY id'); return $this->db->doSelect($queryData); diff --git a/lib/SP/Infrastructure/Plugin/Repositories/PluginDataModel.php b/lib/SP/Infrastructure/Plugin/Repositories/PluginDataModel.php index a35e41ca..e0bf25f7 100644 --- a/lib/SP/Infrastructure/Plugin/Repositories/PluginDataModel.php +++ b/lib/SP/Infrastructure/Plugin/Repositories/PluginDataModel.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,14 +25,14 @@ namespace SP\Infrastructure\Plugin\Repositories; use SP\DataModel\EncryptedModel; -use SP\Domain\Common\Adapters\HydratableInterface; +use SP\Domain\Common\Models\HydratableModel; use SP\Domain\Common\Models\Model; use SP\Domain\Common\Models\SerializedModel; /** * Class PluginDataModel */ -final class PluginDataModel extends Model implements HydratableInterface +final class PluginDataModel extends Model implements HydratableModel { use SerializedModel; use EncryptedModel; diff --git a/lib/SP/Infrastructure/Plugin/Repositories/PluginModel.php b/lib/SP/Infrastructure/Plugin/Repositories/PluginModel.php index 86a2a8f8..91f721a7 100644 --- a/lib/SP/Infrastructure/Plugin/Repositories/PluginModel.php +++ b/lib/SP/Infrastructure/Plugin/Repositories/PluginModel.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -24,13 +24,13 @@ namespace SP\Infrastructure\Plugin\Repositories; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Common\Models\Model; /** * Class PluginModel */ -class PluginModel extends Model implements DataModelInterface +class PluginModel extends Model implements ItemWithIdAndNameModel { protected ?int $id = null; protected ?string $name = null; diff --git a/lib/SP/Infrastructure/User/Repositories/UserProfileBaseRepository.php b/lib/SP/Infrastructure/User/Repositories/UserProfileBaseRepository.php index b947ada5..070c41e4 100644 --- a/lib/SP/Infrastructure/User/Repositories/UserProfileBaseRepository.php +++ b/lib/SP/Infrastructure/User/Repositories/UserProfileBaseRepository.php @@ -25,7 +25,7 @@ namespace SP\Infrastructure\User\Repositories; use SP\DataModel\ItemSearchData; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\User\Ports\UserProfileRepository; @@ -111,7 +111,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf public function getById(int $id): QueryResult { $queryData = new QueryData(); - $queryData->setMapClassName(UserProfileData::class); + $queryData->setMapClassName(UserProfileItemWithIdAndName::class); $queryData->setQuery('SELECT id, `name`, `profile` FROM UserProfile WHERE id = ? LIMIT 1'); $queryData->addParam($id); @@ -128,7 +128,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf public function getAll(): QueryResult { $queryData = new QueryData(); - $queryData->setMapClassName(UserProfileData::class); + $queryData->setMapClassName(UserProfileItemWithIdAndName::class); $queryData->setQuery('SELECT id, `name` FROM UserProfile ORDER BY `name`'); return $this->db->doSelect($queryData); @@ -153,7 +153,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf 'SELECT id, `name` FROM UserProfile WHERE id IN ('.$this->buildParamsFromArray($ids).')'; $queryData = new QueryData(); - $queryData->setMapClassName(UserProfileData::class); + $queryData->setMapClassName(UserProfileItemWithIdAndName::class); $queryData->setQuery($query); $queryData->setParams($ids); @@ -217,7 +217,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf /** * Creates an item * - * @param UserProfileData $itemData + * @param UserProfileItemWithIdAndName $itemData * * @return int * @throws ConstraintException @@ -244,7 +244,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf /** * Checks whether the item is duplicated on adding * - * @param UserProfileData $itemData + * @param UserProfileItemWithIdAndName $itemData * * @return bool * @throws ConstraintException @@ -262,7 +262,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf /** * Updates an item * - * @param UserProfileData $itemData + * @param UserProfileItemWithIdAndName $itemData * * @return int * @throws ConstraintException @@ -293,7 +293,7 @@ final class UserProfileBaseRepository extends BaseRepository implements UserProf /** * Checks whether the item is duplicated on updating * - * @param UserProfileData $itemData + * @param UserProfileItemWithIdAndName $itemData * * @return bool * @throws ConstraintException diff --git a/lib/SP/Mvc/View/Components/SelectItemAdapter.php b/lib/SP/Mvc/View/Components/SelectItemAdapter.php index 248983b4..0845c0b0 100644 --- a/lib/SP/Mvc/View/Components/SelectItemAdapter.php +++ b/lib/SP/Mvc/View/Components/SelectItemAdapter.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -25,7 +25,7 @@ namespace SP\Mvc\View\Components; use RuntimeException; -use SP\Domain\Common\Adapters\DataModelInterface; +use SP\Domain\Common\Models\ItemWithIdAndNameModel; use SP\Domain\Core\Exceptions\SPException; use SP\Http\JsonResponse; @@ -76,7 +76,7 @@ final class SelectItemAdapter implements ItemAdapterInterface $out = []; foreach ($this->items as $item) { - if (!$item instanceof DataModelInterface) { + if (!$item instanceof ItemWithIdAndNameModel) { throw new RuntimeException(__u('Wrong object type')); } @@ -137,7 +137,7 @@ final class SelectItemAdapter implements ItemAdapterInterface { return array_map( static function ($item) { - if (!$item instanceof DataModelInterface) { + if (!$item instanceof ItemWithIdAndNameModel) { throw new RuntimeException(__u('Wrong object type')); } diff --git a/lib/SP/Providers/Notification/NotificationHandler.php b/lib/SP/Providers/Notification/NotificationHandler.php index 14841c30..49dececa 100644 --- a/lib/SP/Providers/Notification/NotificationHandler.php +++ b/lib/SP/Providers/Notification/NotificationHandler.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -27,7 +27,7 @@ namespace SP\Providers\Notification; use Exception; use SP\Core\Application; use SP\Core\Events\Event; -use SP\DataModel\NotificationData; +use SP\DataModel\NotificationItemWithIdAndName; use SP\Domain\Core\Events\EventReceiver; use SP\Domain\Notification\Ports\NotificationServiceInterface; use SP\Providers\EventsTrait; @@ -96,7 +96,7 @@ final class NotificationHandler extends Provider implements EventReceiver $userIds = $eventMessage !== null ? $eventMessage->getExtra('userId') : []; foreach ($userIds as $userId) { - $notificationData = new NotificationData(); + $notificationData = new NotificationItemWithIdAndName(); $notificationData->setType(__('Request')); $notificationData->setComponent(__('Accounts')); $notificationData->setUserId($userId); @@ -107,9 +107,9 @@ final class NotificationHandler extends Provider implements EventReceiver } /** - * @param NotificationData $notificationData + * @param NotificationItemWithIdAndName $notificationData */ - private function notify(NotificationData $notificationData): void + private function notify(NotificationItemWithIdAndName $notificationData): void { try { $this->notificationService->create($notificationData); @@ -129,7 +129,7 @@ final class NotificationHandler extends Provider implements EventReceiver if ($notify[0] === true) { $userId = $eventMessage->getExtra('userId')[0]; - $notificationData = new NotificationData(); + $notificationData = new NotificationItemWithIdAndName(); $notificationData->setType(__('Notification')); $notificationData->setComponent(__('Accounts')); $notificationData->setUserId($userId); diff --git a/lib/SP/Util/FileUtil.php b/lib/SP/Util/FileUtil.php index fd67fdd2..db8437d1 100644 --- a/lib/SP/Util/FileUtil.php +++ b/lib/SP/Util/FileUtil.php @@ -4,7 +4,7 @@ * * @author nuxsmin * @link https://syspass.org - * @copyright 2012-2023, Rubén Domínguez nuxsmin@$syspass.org + * @copyright 2012-2024, Rubén Domínguez nuxsmin@$syspass.org * * This file is part of sysPass. * @@ -27,7 +27,7 @@ namespace SP\Util; use FilesystemIterator; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; -use SP\DataModel\FileData; +use SP\DataModel\FileItemWithIdAndName; use SP\Domain\Core\Exceptions\FileNotFoundException; use SP\Domain\Core\Exceptions\InvalidClassException; use SP\Infrastructure\File\FileException; @@ -80,7 +80,7 @@ class FileUtil return rmdir($dir); } - public static function isImage(FileData $fileData): bool + public static function isImage(FileItemWithIdAndName $fileData): bool { return in_array(strtolower($fileData->getType()), self::IMAGE_MIME, true); } diff --git a/tests/SPT/Core/Acl/ActionsTest.php b/tests/SPT/Core/Acl/ActionsTest.php index 2b817f20..9e074e83 100644 --- a/tests/SPT/Core/Acl/ActionsTest.php +++ b/tests/SPT/Core/Acl/ActionsTest.php @@ -28,7 +28,7 @@ use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\MockObject\MockObject; use SP\Core\Acl\Actions; use SP\Core\Context\ContextException; -use SP\DataModel\ActionData; +use SP\DataModel\ActionItemWithIdAndName; use SP\Domain\Core\Acl\ActionNotFoundException; use SP\Domain\Storage\Ports\FileCacheService; use SP\Domain\Storage\Ports\XmlFileStorageService; @@ -106,7 +106,7 @@ class ActionsTest extends UnitaryTestCase } /** - * @return ActionData[] + * @return ActionItemWithIdAndName[] */ private function checkLoadAndSave(): array { @@ -124,7 +124,7 @@ class ActionsTest extends UnitaryTestCase ->willReturn($actions); $actionsMapped = array_map( - static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']), + static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']), $actions ); @@ -172,7 +172,7 @@ class ActionsTest extends UnitaryTestCase $actions = $this->getActions(); $actionsMapped = array_map( - static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']), + static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']), $actions ); @@ -272,7 +272,7 @@ class ActionsTest extends UnitaryTestCase ->willReturn($actions); $actionsMapped = array_map( - static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']), + static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']), $actions ); @@ -292,7 +292,7 @@ class ActionsTest extends UnitaryTestCase public function testGetActionById() { $actionsMapped = array_map( - static fn(array $a) => new ActionData($a['id'], $a['name'], $a['text'], $a['route']), + static fn(array $a) => new ActionItemWithIdAndName($a['id'], $a['name'], $a['text'], $a['route']), $this->getActions() ); diff --git a/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php b/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php index cb553b5e..d11b9dc8 100644 --- a/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php +++ b/tests/SPT/Domain/Account/Adapters/AccountAdapterTest.php @@ -27,7 +27,7 @@ namespace SPT\Domain\Account\Adapters; use League\Fractal\Manager; use League\Fractal\Resource\Item; use PHPUnit\Framework\MockObject\Exception; -use SP\DataModel\ActionData; +use SP\DataModel\ActionItemWithIdAndName; use SP\Domain\Account\Adapters\AccountAdapter; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Acl\ActionNotFoundException; @@ -57,7 +57,7 @@ class AccountAdapterTest extends UnitaryTestCase ->method('getActionById') ->with(AclActionsInterface::ACCOUNT_VIEW) ->willReturn( - new ActionData( + new ActionItemWithIdAndName( self::$faker->randomNumber(), self::$faker->colorName, self::$faker->sentence, @@ -140,7 +140,7 @@ class AccountAdapterTest extends UnitaryTestCase ->method('getActionById') ->with(AclActionsInterface::ACCOUNT_VIEW) ->willReturn( - new ActionData( + new ActionItemWithIdAndName( self::$faker->randomNumber(), self::$faker->colorName, self::$faker->sentence, diff --git a/tests/SPT/Domain/Account/Services/AccountAclTest.php b/tests/SPT/Domain/Account/Services/AccountAclTest.php index cb82b9e3..0b39e222 100644 --- a/tests/SPT/Domain/Account/Services/AccountAclTest.php +++ b/tests/SPT/Domain/Account/Services/AccountAclTest.php @@ -26,7 +26,7 @@ namespace SPT\Domain\Account\Services; use PHPUnit\Framework\MockObject\Exception; use SP\Core\Acl\Acl; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Adapters\AccountPermission; use SP\Domain\Account\Dtos\AccountAclDto; use SP\Domain\Account\Services\AccountAcl; @@ -75,8 +75,8 @@ class AccountAclTest extends UnitaryTestCase 'isPrivateGroup' => 0, 'otherUserGroupEdit' => 0, 'otherUserEdit' => 0, - 'users' => [new ItemData(['id' => 3, 'isEdit' => 1])], - 'groups' => [new ItemData(['id' => 2, 'isEdit' => 1])], + 'users' => [new ItemItemWithIdAndName(['id' => 3, 'isEdit' => 1])], + 'groups' => [new ItemItemWithIdAndName(['id' => 2, 'isEdit' => 1])], ], 2 => [ @@ -88,8 +88,8 @@ class AccountAclTest extends UnitaryTestCase 'otherUserEdit' => 0, 'users' => [], 'groups' => [ - new ItemData(['id' => 2, 'isEdit' => 1]), - new ItemData(['id' => 3, 'isEdit' => 1]), + new ItemItemWithIdAndName(['id' => 2, 'isEdit' => 1]), + new ItemItemWithIdAndName(['id' => 3, 'isEdit' => 1]), ], ], 3 => [ diff --git a/tests/SPT/Domain/Account/Services/AccountFileTest.php b/tests/SPT/Domain/Account/Services/AccountFileTest.php index 51161d47..0115434c 100644 --- a/tests/SPT/Domain/Account/Services/AccountFileTest.php +++ b/tests/SPT/Domain/Account/Services/AccountFileTest.php @@ -25,8 +25,8 @@ namespace SPT\Domain\Account\Services; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\FileData; use SP\DataModel\FileExtData; +use SP\DataModel\FileItemWithIdAndName; use SP\Domain\Account\Ports\AccountFileRepository; use SP\Domain\Account\Services\AccountFile; use SP\Domain\Common\Services\ServiceException; @@ -59,8 +59,8 @@ class AccountFileTest extends UnitaryTestCase */ public function testCreate(): void { - $fileData = FileData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()) - ->mutate( + $fileData = FileItemWithIdAndName::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()) + ->mutate( ['type' => self::$faker->mimeType()] ); @@ -83,7 +83,7 @@ class AccountFileTest extends UnitaryTestCase */ public function testCreateWithThumbnail(): void { - $fileData = FileData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()); + $fileData = FileItemWithIdAndName::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()); $this->accountFileRepository ->expects(self::once()) @@ -221,7 +221,7 @@ class AccountFileTest extends UnitaryTestCase */ public function testGetByAccountId(): void { - $fileData = FileData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()); + $fileData = FileItemWithIdAndName::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()); $queryResult = new QueryResult([$fileData]); diff --git a/tests/SPT/Domain/Account/Services/AccountPresetTest.php b/tests/SPT/Domain/Account/Services/AccountPresetTest.php index 929e5c59..5d89b7b4 100644 --- a/tests/SPT/Domain/Account/Services/AccountPresetTest.php +++ b/tests/SPT/Domain/Account/Services/AccountPresetTest.php @@ -34,7 +34,7 @@ use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\ValidationException; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Mvc\Controller\Validators\ValidatorInterface; use SPT\Generators\AccountDataGenerator; use SPT\Generators\ItemPresetDataGenerator; @@ -48,8 +48,8 @@ use SPT\UnitaryTestCase; class AccountPresetTest extends UnitaryTestCase { - private ItemPresetServiceInterface|MockObject $itemPresetService; - private AccountPreset $accountPreset; + private ItemPresetService|MockObject $itemPresetService; + private AccountPreset $accountPreset; private ValidatorInterface|MockObject $passwordValidator; /** @@ -170,7 +170,7 @@ class AccountPresetTest extends UnitaryTestCase $configData = $this->config->getConfigData(); $configData->setAccountExpireEnabled(true); - $this->itemPresetService = $this->createMock(ItemPresetServiceInterface::class); + $this->itemPresetService = $this->createMock(ItemPresetService::class); $this->passwordValidator = $this->createMock(ValidatorInterface::class); $this->accountToUserGroupRepository = $this->createMock(AccountToUserGroupRepository::class); $this->accountToUserRepository = $this->createMock(AccountToUserRepository::class); diff --git a/tests/SPT/Domain/Account/Services/AccountTest.php b/tests/SPT/Domain/Account/Services/AccountTest.php index 211f928c..7f41eb35 100644 --- a/tests/SPT/Domain/Account/Services/AccountTest.php +++ b/tests/SPT/Domain/Account/Services/AccountTest.php @@ -32,7 +32,6 @@ use SP\Domain\Account\Dtos\AccountUpdateBulkDto; use SP\Domain\Account\Dtos\AccountUpdateDto; use SP\Domain\Account\Dtos\EncryptedPassword; use SP\Domain\Account\Models\Account as AccountModel; -use SP\Domain\Account\Models\ItemPreset; use SP\Domain\Account\Ports\AccountCryptService; use SP\Domain\Account\Ports\AccountHistoryService; use SP\Domain\Account\Ports\AccountItemsService; @@ -48,8 +47,9 @@ use SP\Domain\Config\Ports\ConfigService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; +use SP\Domain\ItemPreset\Models\ItemPreset; use SP\Domain\ItemPreset\Ports\ItemPresetInterface; -use SP\Domain\ItemPreset\Ports\ItemPresetServiceInterface; +use SP\Domain\ItemPreset\Ports\ItemPresetService; use SP\Infrastructure\Common\Repositories\NoSuchItemException; use SP\Infrastructure\Database\QueryResult; use SPT\Generators\AccountDataGenerator; @@ -67,9 +67,9 @@ class AccountTest extends UnitaryTestCase private AccountRepository|MockObject $accountRepository; private AccountToUserGroupRepository|MockObject $accountToUserGroupRepository; private AccountToUserRepository|MockObject $accountToUserRepository; - private AccountToTagRepository|MockObject $accountToTagRepository; - private ItemPresetServiceInterface|MockObject $itemPresetService; - private AccountHistoryService|MockObject $accountHistoryService; + private AccountToTagRepository|MockObject $accountToTagRepository; + private ItemPresetService|MockObject $itemPresetService; + private AccountHistoryService|MockObject $accountHistoryService; private ConfigService|MockObject $configService; private AccountCryptService|MockObject $accountCryptService; private AccountPresetService|MockObject $accountPresetService; @@ -1329,7 +1329,7 @@ class AccountTest extends UnitaryTestCase $this->accountToUserGroupRepository = $this->createMock(AccountToUserGroupRepository::class); $this->accountToUserRepository = $this->createMock(AccountToUserRepository::class); $this->accountToTagRepository = $this->createMock(AccountToTagRepository::class); - $this->itemPresetService = $this->createMock(ItemPresetServiceInterface::class); + $this->itemPresetService = $this->createMock(ItemPresetService::class); $this->accountHistoryService = $this->createMock(AccountHistoryService::class); $this->configService = $this->createMock(ConfigService::class); $this->accountCryptService = $this->createMock(AccountCryptService::class); diff --git a/tests/SPT/Domain/Account/Services/AccountToTagTest.php b/tests/SPT/Domain/Account/Services/AccountToTagTest.php index 4a80ae02..c7a63c69 100644 --- a/tests/SPT/Domain/Account/Services/AccountToTagTest.php +++ b/tests/SPT/Domain/Account/Services/AccountToTagTest.php @@ -25,7 +25,7 @@ namespace SPT\Domain\Account\Services; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToTagRepository; use SP\Domain\Account\Services\AccountToTag; use SP\Domain\Common\Models\Simple; @@ -67,7 +67,7 @@ class AccountToTagTest extends UnitaryTestCase $actual = $this->accountToTag->getTagsByAccountId($accountId); $expected = $result->getData(Simple::class)->toArray(null, null, true); - $this->assertTrue($actual[0] instanceof ItemData); + $this->assertTrue($actual[0] instanceof ItemItemWithIdAndName); $this->assertEquals($expected, $actual[0]->toArray()); } diff --git a/tests/SPT/Domain/Account/Services/AccountToUserGroupTest.php b/tests/SPT/Domain/Account/Services/AccountToUserGroupTest.php index e625c154..ac8f958c 100644 --- a/tests/SPT/Domain/Account/Services/AccountToUserGroupTest.php +++ b/tests/SPT/Domain/Account/Services/AccountToUserGroupTest.php @@ -25,7 +25,7 @@ namespace SPT\Domain\Account\Services; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToUserGroupRepository; use SP\Domain\Account\Services\AccountToUserGroup; use SP\Domain\Core\Exceptions\ConstraintException; @@ -57,7 +57,7 @@ class AccountToUserGroupTest extends UnitaryTestCase $result = new QueryResult( [ - new ItemData( + new ItemItemWithIdAndName( [ 'id' => self::$faker->randomNumber(), 'name' => self::$faker->colorName, @@ -74,9 +74,9 @@ class AccountToUserGroupTest extends UnitaryTestCase ->willReturn($result); $actual = $this->accountToUserGroup->getUserGroupsByAccountId($accountId); - $expected = $result->getData(ItemData::class)->toArray(null, null, true); + $expected = $result->getData(ItemItemWithIdAndName::class)->toArray(null, null, true); - $this->assertTrue($actual[0] instanceof ItemData); + $this->assertTrue($actual[0] instanceof ItemItemWithIdAndName); $this->assertEquals($expected, $actual[0]->toArray(null, null, true)); } diff --git a/tests/SPT/Domain/Account/Services/AccountToUserTest.php b/tests/SPT/Domain/Account/Services/AccountToUserTest.php index 72c15a03..039ae6f1 100644 --- a/tests/SPT/Domain/Account/Services/AccountToUserTest.php +++ b/tests/SPT/Domain/Account/Services/AccountToUserTest.php @@ -25,7 +25,7 @@ namespace SPT\Domain\Account\Services; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountToUserRepository; use SP\Domain\Account\Services\AccountToUser; use SP\Domain\Core\Exceptions\ConstraintException; @@ -57,7 +57,7 @@ class AccountToUserTest extends UnitaryTestCase $result = new QueryResult( [ - new ItemData( + new ItemItemWithIdAndName( [ 'id' => self::$faker->randomNumber(), 'name' => self::$faker->colorName, @@ -75,9 +75,9 @@ class AccountToUserTest extends UnitaryTestCase ->willReturn($result); $actual = $this->accountToUser->getUsersByAccountId($accountId); - $expected = $result->getData(ItemData::class)->toArray(null, null, true); + $expected = $result->getData(ItemItemWithIdAndName::class)->toArray(null, null, true); - $this->assertTrue($actual[0] instanceof ItemData); + $this->assertTrue($actual[0] instanceof ItemItemWithIdAndName); $this->assertEquals($expected, $actual[0]->toArray(null, null, true)); } diff --git a/tests/SPT/Domain/Export/Services/XmlAccountExportTest.php b/tests/SPT/Domain/Export/Services/XmlAccountExportTest.php index 851d1ed4..72dc8d77 100644 --- a/tests/SPT/Domain/Export/Services/XmlAccountExportTest.php +++ b/tests/SPT/Domain/Export/Services/XmlAccountExportTest.php @@ -28,7 +28,7 @@ use DOMDocument; use PHPUnit\Framework\MockObject\Exception; use PHPUnit\Framework\MockObject\MockObject; use RuntimeException; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Account\Ports\AccountToTagService; use SP\Domain\Common\Services\ServiceException; @@ -56,7 +56,7 @@ class XmlAccountExportTest extends UnitaryTestCase public function testExport() { $account = AccountDataGenerator::factory()->buildAccount(); - $tag = new ItemData(['id' => self::$faker->randomNumber(3)]); + $tag = new ItemItemWithIdAndName(['id' => self::$faker->randomNumber(3)]); $document = new DOMDocument(); diff --git a/tests/SPT/Domain/ItemPreset/Services/ItemPresetTest.php b/tests/SPT/Domain/ItemPreset/Services/ItemPresetTest.php new file mode 100644 index 00000000..c643b0b5 --- /dev/null +++ b/tests/SPT/Domain/ItemPreset/Services/ItemPresetTest.php @@ -0,0 +1,322 @@ +. + */ + +namespace SPT\Domain\ItemPreset\Services; + +use PHPUnit\Framework\MockObject\Exception; +use PHPUnit\Framework\MockObject\MockObject; +use SP\Domain\Common\Services\ServiceException; +use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel; +use SP\Domain\ItemPreset\Ports\ItemPresetRepository; +use SP\Domain\ItemPreset\Services\ItemPreset; +use SP\Infrastructure\Common\Repositories\NoSuchItemException; +use SP\Infrastructure\Database\QueryResult; +use SPT\Generators\ItemPresetDataGenerator; +use SPT\Generators\ItemSearchDataGenerator; +use SPT\UnitaryTestCase; + +/** + * Class ItemPresetTest + * + * @group unitary + */ +class ItemPresetTest extends UnitaryTestCase +{ + + private ItemPresetRepository|MockObject $itemPresetRepository; + private ItemPreset $itemPreset; + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testUpdate() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']); + + $this->itemPresetRepository + ->expects(self::once()) + ->method('update') + ->with($itemPreset) + ->willReturn(1); + + $this->itemPreset->update($itemPreset); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testGetForUser() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']); + + $this->itemPresetRepository + ->expects(self::once()) + ->method('getByFilter') + ->with('test', 100, 200, 300) + ->willReturn(new QueryResult([$itemPreset])); + + $out = $this->itemPreset->getForUser('test', 100, 200, 300); + + $this->assertEquals($itemPreset, $out); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testCreate() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']); + + $queryResult = new QueryResult([]); + + $this->itemPresetRepository + ->expects(self::once()) + ->method('create') + ->with($itemPreset) + ->willReturn($queryResult->setLastId(100)); + + $this->assertEquals(100, $this->itemPreset->create($itemPreset)); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testGetForCurrentUser() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']); + + $userData = $this->context->getUserData(); + + $this->itemPresetRepository + ->expects(self::once()) + ->method('getByFilter') + ->with('test', $userData->getId(), $userData->getUserGroupId(), $userData->getUserProfileId()) + ->willReturn(new QueryResult([$itemPreset])); + + $out = $this->itemPreset->getForCurrentUser('test'); + + $this->assertEquals($itemPreset, $out); + } + + /** + * @throws ConstraintException + * @throws ServiceException + * @throws QueryException + */ + public function testDeleteByIdBatch() + { + $ids = array_map(static fn() => self::$faker->randomNumber(3), range(0, 4)); + + $queryResult = new QueryResult([]); + + $this->itemPresetRepository + ->expects(self::once()) + ->method('deleteByIdBatch') + ->with($ids) + ->willReturn($queryResult->setAffectedNumRows(5)); + + $this->assertEquals(5, $this->itemPreset->deleteByIdBatch($ids)); + } + + /** + * @throws ConstraintException + * @throws ServiceException + * @throws QueryException + */ + public function testDeleteByIdBatchWithException() + { + $ids = array_map(static fn() => self::$faker->randomNumber(3), range(0, 4)); + + $queryResult = new QueryResult([]); + + $this->itemPresetRepository + ->expects(self::once()) + ->method('deleteByIdBatch') + ->with($ids) + ->willReturn($queryResult->setAffectedNumRows(4)); + + $this->expectException(ServiceException::class); + $this->expectExceptionMessage('Error while deleting the values'); + + $this->itemPreset->deleteByIdBatch($ids); + } + + /** + * @throws Exception + */ + public function testGetAll() + { + $queryResult = $this->createMock(QueryResult::class); + $queryResult->expects($this->once()) + ->method('getDataAsArray') + ->with(ItemPresetModel::class) + ->willReturn([1]); + + $this->itemPresetRepository + ->expects($this->once()) + ->method('getAll') + ->willReturn($queryResult); + + $out = $this->itemPreset->getAll(); + + $this->assertEquals([1], $out); + } + + /** + * @throws NoSuchItemException + * @throws Exception + */ + public function testGetById() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']); + + $queryResult = $this->createMock(QueryResult::class); + $queryResult->expects($this->once()) + ->method('getNumRows') + ->willReturn(1); + + $queryResult->expects($this->once()) + ->method('getData') + ->with(ItemPresetModel::class) + ->willReturn($itemPreset); + + $this->itemPresetRepository + ->expects($this->once()) + ->method('getById') + ->with(100) + ->willReturn($queryResult); + + $out = $this->itemPreset->getById(100); + + $this->assertEquals($itemPreset, $out); + } + + /** + * @throws NoSuchItemException + * @throws Exception + */ + public function testGetByIdWithNoRows() + { + $queryResult = $this->createMock(QueryResult::class); + $queryResult->expects($this->once()) + ->method('getNumRows') + ->willReturn(0); + + $this->itemPresetRepository + ->expects($this->once()) + ->method('getById') + ->with(100) + ->willReturn($queryResult); + + $this->expectException(NoSuchItemException::class); + $this->expectExceptionMessage('Value not found'); + + $this->itemPreset->getById(100); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testSearch() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData((object)['foo' => 'bar']); + $itemSearchData = ItemSearchDataGenerator::factory()->buildItemSearchData(); + + $queryResult = new QueryResult([$itemPreset]); + + $this->itemPresetRepository + ->expects($this->once()) + ->method('search') + ->with($itemSearchData) + ->willReturn($queryResult); + + $out = $this->itemPreset->search($itemSearchData); + + $this->assertEquals($queryResult, $out); + } + + /** + * @throws NoSuchItemException + * @throws Exception + * @throws ConstraintException + * @throws QueryException + */ + public function testDelete() + { + $queryResult = $this->createMock(QueryResult::class); + $queryResult->expects($this->once()) + ->method('getAffectedNumRows') + ->willReturn(1); + + $this->itemPresetRepository + ->expects($this->once()) + ->method('delete') + ->with(100) + ->willReturn($queryResult); + + $this->itemPreset->delete(100); + } + + /** + * @throws NoSuchItemException + * @throws Exception + * @throws ConstraintException + * @throws QueryException + */ + public function testDeleteWithNoRows() + { + $queryResult = $this->createMock(QueryResult::class); + $queryResult->expects($this->once()) + ->method('getAffectedNumRows') + ->willReturn(0); + + $this->itemPresetRepository + ->expects($this->once()) + ->method('delete') + ->with(100) + ->willReturn($queryResult); + + $this->expectException(NoSuchItemException::class); + $this->expectExceptionMessage('Value not found'); + + $this->itemPreset->delete(100); + } + + + protected function setUp(): void + { + parent::setUp(); + + $this->itemPresetRepository = $this->createMock(ItemPresetRepository::class); + + $this->itemPreset = new ItemPreset($this->application, $this->itemPresetRepository); + } +} diff --git a/tests/SPT/Generators/AccountDataGenerator.php b/tests/SPT/Generators/AccountDataGenerator.php index eb3e15d5..de8e315e 100644 --- a/tests/SPT/Generators/AccountDataGenerator.php +++ b/tests/SPT/Generators/AccountDataGenerator.php @@ -24,7 +24,7 @@ namespace SPT\Generators; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Account\Dtos\AccountCreateDto; use SP\Domain\Account\Dtos\AccountEnrichedDto; use SP\Domain\Account\Dtos\AccountHistoryDto; @@ -94,12 +94,12 @@ final class AccountDataGenerator extends DataGenerator } /** - * @return ItemData[] + * @return ItemItemWithIdAndName[] */ public function buildItemData(): array { return array_map( - fn() => new ItemData(['id' => $this->faker->randomNumber(3), 'name' => $this->faker->name]), + fn() => new ItemItemWithIdAndName(['id' => $this->faker->randomNumber(3), 'name' => $this->faker->name]), range(0, 9) ); } diff --git a/tests/SPT/Generators/ItemPresetDataGenerator.php b/tests/SPT/Generators/ItemPresetDataGenerator.php index 6b95fc01..4ee445f2 100644 --- a/tests/SPT/Generators/ItemPresetDataGenerator.php +++ b/tests/SPT/Generators/ItemPresetDataGenerator.php @@ -26,7 +26,7 @@ namespace SPT\Generators; use SP\DataModel\ItemPreset\AccountPrivate; use SP\DataModel\ItemPreset\Password; -use SP\Domain\Account\Models\ItemPreset; +use SP\Domain\ItemPreset\Models\ItemPreset; /** * Class ItemPresetDataGenerator @@ -37,14 +37,14 @@ final class ItemPresetDataGenerator extends DataGenerator { return new ItemPreset([ 'id' => $this->faker->randomNumber(3), - 'type' => $this->faker->colorName, + 'type' => $this->faker->colorName, 'userId' => $this->faker->randomNumber(3), 'userGroupId' => $this->faker->randomNumber(3), 'userProfileId' => $this->faker->randomNumber(3), - 'fixed' => (int)$this->faker->boolean, + 'fixed' => (int)$this->faker->boolean, 'priority' => $this->faker->randomNumber(3), - 'data' => serialize($data), - ]); + 'data' => serialize($data), + ]); } public function buildPassword(): Password diff --git a/tests/SPT/Generators/UserProfileDataGenerator.php b/tests/SPT/Generators/UserProfileDataGenerator.php index 2ffad240..30ab9360 100644 --- a/tests/SPT/Generators/UserProfileDataGenerator.php +++ b/tests/SPT/Generators/UserProfileDataGenerator.php @@ -25,16 +25,16 @@ namespace SPT\Generators; use SP\DataModel\ProfileData; -use SP\DataModel\UserProfileData; +use SP\DataModel\UserProfileItemWithIdAndName; /** * Class UserProfileDataGenerator */ final class UserProfileDataGenerator extends DataGenerator { - public function buildUserProfileData(): UserProfileData + public function buildUserProfileData(): UserProfileItemWithIdAndName { - return new UserProfileData($this->getUserProfileProperties()); + return new UserProfileItemWithIdAndName($this->getUserProfileProperties()); } private function getUserProfileProperties(): array diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php index 3a006eef..030bc7b5 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountFileTest.php @@ -27,7 +27,7 @@ namespace SPT\Infrastructure\Account\Repositories; use Aura\SqlQuery\QueryFactory; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\FileData; +use SP\DataModel\FileItemWithIdAndName; use SP\DataModel\ItemSearchData; use SP\Domain\Common\Models\Simple; use SP\Domain\Core\Exceptions\ConstraintException; @@ -95,7 +95,7 @@ class AccountFileTest extends UnitaryTestCase */ public function testCreate(): void { - $fileData = FileData::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()); + $fileData = FileItemWithIdAndName::buildFromSimpleModel(FileDataGenerator::factory()->buildFileData()); $expected = new QueryResult(); $expected->setLastId(1); diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php index b7a248cf..427e7408 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserGroupTest.php @@ -27,7 +27,7 @@ namespace SPT\Infrastructure\Account\Repositories; use Aura\SqlQuery\QueryFactory; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Infrastructure\Account\Repositories\AccountToUserGroup; @@ -84,7 +84,7 @@ class AccountToUserGroupTest extends UnitaryTestCase $query = $arg->getQuery(); return $query->getBindValues()['accountId'] === $id - && $arg->getMapClassName() === ItemData::class + && $arg->getMapClassName() === ItemItemWithIdAndName::class && !empty($query->getStatement()); } ); @@ -189,7 +189,7 @@ class AccountToUserGroupTest extends UnitaryTestCase $query = $arg->getQuery(); return $query->getBindValues()['userGroupId'] === $id - && $arg->getMapClassName() === ItemData::class + && $arg->getMapClassName() === ItemItemWithIdAndName::class && !empty($query->getStatement()); } ); diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php index b819a469..f9946136 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountToUserTest.php @@ -27,7 +27,7 @@ namespace SPT\Infrastructure\Account\Repositories; use Aura\SqlQuery\QueryFactory; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\ItemData; +use SP\DataModel\ItemItemWithIdAndName; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Infrastructure\Account\Repositories\AccountToUser; @@ -84,7 +84,7 @@ class AccountToUserTest extends UnitaryTestCase $query = $arg->getQuery(); return $query->getBindValues()['accountId'] === $id - && $arg->getMapClassName() === ItemData::class + && $arg->getMapClassName() === ItemItemWithIdAndName::class && !empty($query->getStatement()); } ); diff --git a/tests/SPT/Infrastructure/ItemPreset/Repositories/ItemPresetTest.php b/tests/SPT/Infrastructure/ItemPreset/Repositories/ItemPresetTest.php new file mode 100644 index 00000000..b045c5bc --- /dev/null +++ b/tests/SPT/Infrastructure/ItemPreset/Repositories/ItemPresetTest.php @@ -0,0 +1,339 @@ +. + */ + +namespace SPT\Infrastructure\ItemPreset\Repositories; + +use Aura\SqlQuery\Common\DeleteInterface; +use Aura\SqlQuery\Common\InsertInterface; +use Aura\SqlQuery\Common\SelectInterface; +use Aura\SqlQuery\Common\UpdateInterface; +use Aura\SqlQuery\QueryFactory; +use Exception; +use PHPUnit\Framework\Constraint\Callback; +use SP\DataModel\ItemSearchData; +use SP\Domain\Common\Models\Simple; +use SP\Domain\Core\Exceptions\ConstraintException; +use SP\Domain\Core\Exceptions\QueryException; +use SP\Domain\ItemPreset\Models\ItemPreset as ItemPresetModel; +use SP\Infrastructure\Database\DatabaseInterface; +use SP\Infrastructure\Database\QueryData; +use SP\Infrastructure\Database\QueryResult; +use SP\Infrastructure\ItemPreset\Repositories\ItemPreset; +use SPT\Generators\ItemPresetDataGenerator; +use SPT\UnitaryTestCase; +use stdClass; + +/** + * Class ItemPresetTest + * + * @group unitary + */ +class ItemPresetTest extends UnitaryTestCase +{ + + private ItemPreset $itemPreset; + + public function testGetByFilter() + { + $item = new ItemSearchData(self::$faker->name); + + $callback = new Callback( + static function (QueryData $arg) use ($item) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 4 + && $params['type'] === 'test' + && $params['userId'] === 100 + && $params['userGroupId'] === 200 + && $params['userProfileId'] === 300 + && $arg->getMapClassName() === ItemPresetModel::class + && is_a($query, SelectInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doSelect') + ->with($callback, false); + + $this->itemPreset->getByFilter('test', 100, 200, 300); + } + + public function testDelete() + { + $id = self::$faker->randomNumber(); + + $callback = new Callback( + static function (QueryData $arg) use ($id) { + $query = $arg->getQuery(); + + return $query->getBindValues()['id'] === $id + && is_a($query, DeleteInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database->expects(self::once())->method('doQuery')->with($callback); + + $this->itemPreset->delete($id); + } + + public function testGetAll() + { + $callback = new Callback( + static function (QueryData $arg) { + $query = $arg->getQuery(); + return $arg->getMapClassName() === ItemPresetModel::class + && is_a($query, SelectInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doSelect') + ->with($callback); + + $this->itemPreset->getAll(); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testCreate() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData(new stdClass()); + + $callbackCreate = new Callback( + static function (QueryData $arg) use ($itemPreset) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 7 + && $params['type'] === $itemPreset->getType() + && $params['userId'] === $itemPreset->getUserId() + && $params['userProfileId'] === $itemPreset->getUserProfileId() + && $params['userGroupId'] === $itemPreset->getUserGroupId() + && $params['data'] === $itemPreset->getData() + && $params['fixed'] === $itemPreset->getFixed() + && $params['priority'] === $itemPreset->getPriority() + && is_a($query, InsertInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::exactly(1)) + ->method('doQuery') + ->with($callbackCreate) + ->willReturn(new QueryResult([])); + + $this->itemPreset->create($itemPreset); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testUpdate() + { + $itemPreset = ItemPresetDataGenerator::factory()->buildItemPresetData(new stdClass()); + + $callbackCreate = new Callback( + static function (QueryData $arg) use ($itemPreset) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 8 + && $params['id'] === $itemPreset->getId() + && $params['type'] === $itemPreset->getType() + && $params['userId'] === $itemPreset->getUserId() + && $params['userProfileId'] === $itemPreset->getUserProfileId() + && $params['userGroupId'] === $itemPreset->getUserGroupId() + && $params['data'] === $itemPreset->getData() + && $params['fixed'] === $itemPreset->getFixed() + && $params['priority'] === $itemPreset->getPriority() + && is_a($query, UpdateInterface::class) + && !empty($query->getStatement()); + } + ); + + $queryResult = new QueryResult([]); + + $this->database + ->expects(self::exactly(1)) + ->method('doQuery') + ->with($callbackCreate) + ->willReturn($queryResult->setAffectedNumRows(1)); + + $out = $this->itemPreset->update($itemPreset); + + $this->assertEquals(1, $out); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testSearch() + { + $item = new ItemSearchData(self::$faker->name); + + $callback = new Callback( + static function (QueryData $arg) use ($item) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + $searchStringLike = '%' . $item->getSeachString() . '%'; + + return count($params) === 4 + && $params['type'] === $searchStringLike + && $params['userName'] === $searchStringLike + && $params['userProfileName'] === $searchStringLike + && $params['userGroupName'] === $searchStringLike + && $arg->getMapClassName() === ItemPresetModel::class + && is_a($query, SelectInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doSelect') + ->with($callback, true); + + $this->itemPreset->search($item); + } + + /** + * @throws Exception + */ + public function testSearchWithoutString(): void + { + $callback = new Callback( + static function (QueryData $arg) { + $query = $arg->getQuery(); + return count($query->getBindValues()) === 0 + && $arg->getMapClassName() === ItemPresetModel::class + && is_a($query, SelectInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doSelect') + ->with($callback, true); + + $this->itemPreset->search(new ItemSearchData()); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testDeleteByIdBatch() + { + $ids = [self::$faker->randomNumber(), self::$faker->randomNumber(), self::$faker->randomNumber()]; + + $callback = new Callback( + static function (QueryData $arg) use ($ids) { + $query = $arg->getQuery(); + $values = $query->getBindValues(); + + return count($values) === 3 + && array_shift($values) === array_shift($ids) + && array_shift($values) === array_shift($ids) + && array_shift($values) === array_shift($ids) + && $arg->getMapClassName() === Simple::class + && is_a($query, DeleteInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doQuery') + ->with($callback); + + $this->itemPreset->deleteByIdBatch($ids); + } + + /** + * @throws ConstraintException + * @throws QueryException + */ + public function testDeleteByIdBatchWithNoIds(): void + { + $this->database + ->expects(self::never()) + ->method('doQuery'); + + $this->itemPreset->deleteByIdBatch([]); + } + + public function testGetById() + { + $id = self::$faker->randomNumber(); + + $callback = new Callback( + static function (QueryData $arg) use ($id) { + $query = $arg->getQuery(); + $params = $query->getBindValues(); + + return count($params) === 1 + && $params['id'] === $id + && $arg->getMapClassName() === ItemPresetModel::class + && is_a($query, SelectInterface::class) + && !empty($query->getStatement()); + } + ); + + $this->database + ->expects(self::once()) + ->method('doSelect') + ->with($callback); + + $this->itemPreset->getById($id); + } + + protected function setUp(): void + { + parent::setUp(); + + $this->database = $this->createMock(DatabaseInterface::class); + $queryFactory = new QueryFactory('mysql'); + + $this->itemPreset = new ItemPreset( + $this->database, + $this->context, + $this->application->getEventDispatcher(), + $queryFactory, + ); + } + + +} diff --git a/tests/SPT/UnitaryTestCase.php b/tests/SPT/UnitaryTestCase.php index 8862ea9e..de441599 100644 --- a/tests/SPT/UnitaryTestCase.php +++ b/tests/SPT/UnitaryTestCase.php @@ -85,7 +85,8 @@ abstract class UnitaryTestCase extends TestCase ->setLogin(self::$faker->userName) ->setName(self::$faker->userName) ->setId(self::$faker->randomNumber(2)) - ->setUserGroupId(self::$faker->randomNumber(2)); + ->setUserGroupId(self::$faker->randomNumber(2)) + ->setUserProfileId(self::$faker->randomNumber(2)); $this->context = new StatelessContext(); $this->context->initialize();