From 24fcc0abf481dc7bc9a65331fa4e2a0e05698c07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Tue, 16 Jan 2024 09:25:01 +0100 Subject: [PATCH] chore: Refactor Client naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- .../api/Controllers/Client/ClientBase.php | 10 ++-- .../AccountManager/BulkEditController.php | 20 ++++---- .../web/Controllers/Client/ClientSaveBase.php | 12 ++--- .../web/Controllers/Client/ClientViewBase.php | 8 ++-- .../Controllers/Client/SearchController.php | 14 +++--- .../Helpers/Account/AccountHelper.php | 8 ++-- .../Helpers/Account/AccountHistoryHelper.php | 4 +- .../Helpers/Account/AccountSearchHelper.php | 20 ++++---- .../ItemManager/IndexController.php | 6 +-- .../Controllers/Items/ClientsController.php | 8 ++-- ...toryInterface.php => ClientRepository.php} | 14 +++--- ...ServiceInterface.php => ClientService.php} | 4 +- lib/SP/Domain/Client/Services/Client.php | 14 +++--- .../Export/Services/XmlExportService.php | 22 ++++----- .../Domain/Import/Services/ImportHelper.php | 18 ++++---- lib/SP/Domain/Import/Services/ImportTrait.php | 8 ++-- .../{ClientRepository.php => Client.php} | 40 ++++++++-------- .../SPT/Domain/Client/Services/ClientTest.php | 38 +++++++-------- ...lientRepositoryTest.php => ClientTest.php} | 46 +++++++++---------- 19 files changed, 157 insertions(+), 157 deletions(-) rename lib/SP/Domain/Client/Ports/{ClientRepositoryInterface.php => ClientRepository.php} (90%) rename lib/SP/Domain/Client/Ports/{ClientServiceInterface.php => ClientService.php} (96%) rename lib/SP/Infrastructure/Client/Repositories/{ClientRepository.php => Client.php} (89%) rename tests/SPT/Infrastructure/Client/Repositories/{ClientRepositoryTest.php => ClientTest.php} (91%) diff --git a/app/modules/api/Controllers/Client/ClientBase.php b/app/modules/api/Controllers/Client/ClientBase.php index 56515e45..7e107889 100644 --- a/app/modules/api/Controllers/Client/ClientBase.php +++ b/app/modules/api/Controllers/Client/ClientBase.php @@ -29,7 +29,7 @@ use Klein\Klein; use SP\Core\Application; use SP\Domain\Api\Ports\ApiService; use SP\Domain\Client\Ports\ClientAdapterInterface; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Acl\AclInterface; use SP\Domain\Core\Exceptions\InvalidClassException; use SP\Modules\Api\Controllers\ControllerBase; @@ -40,7 +40,7 @@ use SP\Modules\Api\Controllers\Help\ClientHelp; */ abstract class ClientBase extends ControllerBase { - protected ClientServiceInterface $clientService; + protected ClientService $clientService; protected ClientAdapterInterface $clientAdapter; /** @@ -49,9 +49,9 @@ abstract class ClientBase extends ControllerBase public function __construct( Application $application, Klein $router, - ApiService $apiService, - AclInterface $acl, - ClientServiceInterface $clientService, + ApiService $apiService, + AclInterface $acl, + ClientService $clientService, ClientAdapterInterface $clientAdapter ) { parent::__construct($application, $router, $apiService, $acl); diff --git a/app/modules/web/Controllers/AccountManager/BulkEditController.php b/app/modules/web/Controllers/AccountManager/BulkEditController.php index bc4b090a..120dbd75 100644 --- a/app/modules/web/Controllers/AccountManager/BulkEditController.php +++ b/app/modules/web/Controllers/AccountManager/BulkEditController.php @@ -33,7 +33,7 @@ use SP\Domain\Account\Ports\AccountHistoryService; use SP\Domain\Account\Ports\AccountSearchService; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; use SP\Domain\Tag\Ports\TagServiceInterface; @@ -62,19 +62,19 @@ final class BulkEditController extends ControllerBase private AccountHistoryService $accountHistoryService; private AccountGrid $accountGrid; private CustomFieldServiceInterface $customFieldService; - private CategoryService $categoryService; - private ClientServiceInterface $clientService; - private TagServiceInterface $tagService; + private CategoryService $categoryService; + private ClientService $clientService; + private TagServiceInterface $tagService; private UserServiceInterface $userService; private UserGroupServiceInterface $userGroupService; public function __construct( - Application $application, - WebControllerHelper $webControllerHelper, - CategoryService $categoryService, - ClientServiceInterface $clientService, - TagServiceInterface $tagService, - UserServiceInterface $userService, + Application $application, + WebControllerHelper $webControllerHelper, + CategoryService $categoryService, + ClientService $clientService, + TagServiceInterface $tagService, + UserServiceInterface $userService, UserGroupServiceInterface $userGroupService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Client/ClientSaveBase.php b/app/modules/web/Controllers/Client/ClientSaveBase.php index cc4f4730..083a9718 100644 --- a/app/modules/web/Controllers/Client/ClientSaveBase.php +++ b/app/modules/web/Controllers/Client/ClientSaveBase.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\Client; use SP\Core\Application; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\CustomField\Ports\CustomFieldServiceInterface; use SP\Modules\Web\Controllers\ControllerBase; use SP\Modules\Web\Forms\ClientForm; @@ -37,14 +37,14 @@ use SP\Mvc\Controller\WebControllerHelper; */ abstract class ClientSaveBase extends ControllerBase { - protected \SP\Domain\Client\Ports\ClientServiceInterface $clientService; - protected CustomFieldServiceInterface $customFieldService; + protected ClientService $clientService; + protected CustomFieldServiceInterface $customFieldService; protected ClientForm $form; public function __construct( - Application $application, + Application $application, WebControllerHelper $webControllerHelper, - ClientServiceInterface $clientService, + ClientService $clientService, CustomFieldServiceInterface $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Client/ClientViewBase.php b/app/modules/web/Controllers/Client/ClientViewBase.php index 4b7ca533..b5733c4b 100644 --- a/app/modules/web/Controllers/Client/ClientViewBase.php +++ b/app/modules/web/Controllers/Client/ClientViewBase.php @@ -28,7 +28,7 @@ namespace SP\Modules\Web\Controllers\Client; use SP\Core\Acl\Acl; use SP\Core\Application; use SP\Domain\Client\Models\Client; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; @@ -47,13 +47,13 @@ abstract class ClientViewBase extends ControllerBase { use ItemTrait; - private ClientServiceInterface $clientService; + private ClientService $clientService; private CustomFieldServiceInterface $customFieldService; public function __construct( - Application $application, + Application $application, WebControllerHelper $webControllerHelper, - ClientServiceInterface $clientService, + ClientService $clientService, CustomFieldServiceInterface $customFieldService ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Client/SearchController.php b/app/modules/web/Controllers/Client/SearchController.php index da7b07cf..84ead72f 100644 --- a/app/modules/web/Controllers/Client/SearchController.php +++ b/app/modules/web/Controllers/Client/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. * @@ -27,7 +27,7 @@ namespace SP\Modules\Web\Controllers\Client; use JsonException; use SP\Core\Application; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -48,14 +48,14 @@ final class SearchController extends ControllerBase use ItemTrait; use JsonTrait; - private ClientServiceInterface $clientService; - private ClientGrid $clientGrid; + private ClientService $clientService; + private ClientGrid $clientGrid; public function __construct( - Application $application, + Application $application, WebControllerHelper $webControllerHelper, - ClientServiceInterface $clientService, - ClientGrid $clientGrid + ClientService $clientService, + ClientGrid $clientGrid ) { parent::__construct($application, $webControllerHelper); diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php index 4956bf1d..d177509d 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHelper.php @@ -39,7 +39,7 @@ use SP\Domain\Account\Ports\AccountService; use SP\Domain\Account\Ports\PublicLinkService; use SP\Domain\Account\Services\PublicLink; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Acl\AccountPermissionException; use SP\Domain\Core\Acl\AclActionsInterface; @@ -79,8 +79,8 @@ final class AccountHelper extends AccountHelperBase private ItemPresetServiceInterface $itemPresetService; private MasterPassServiceInterface $masterPassService; private AccountAclService $accountAclService; - private CategoryService $categoryService; - private ClientServiceInterface $clientService; + private CategoryService $categoryService; + private ClientService $clientService; private CustomFieldServiceInterface $customFieldService; private ?AccountPermission $accountAcl = null; private ?int $accountId = null; @@ -101,7 +101,7 @@ final class AccountHelper extends AccountHelperBase AccountActionsHelper $accountActionsHelper, AccountAclService $accountAclService, CategoryService $categoryService, - ClientServiceInterface $clientService, + ClientService $clientService, CustomFieldServiceInterface $customFieldService, UserServiceInterface $userService, UserGroupServiceInterface $userGroupService, diff --git a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php index e3b4e503..cda9f5bd 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountHistoryHelper.php @@ -33,7 +33,7 @@ use SP\Domain\Account\Ports\AccountHistoryService; use SP\Domain\Account\Ports\AccountToUserGroupService; use SP\Domain\Account\Ports\AccountToUserService; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Acl\AccountPermissionException; use SP\Domain\Core\Acl\AclInterface; @@ -68,7 +68,7 @@ final class AccountHistoryHelper extends AccountHelperBase private AccountHistoryService $accountHistoryService, private AccountAclService $accountAclService, private CategoryService $categoryService, - private ClientServiceInterface $clientService, + private ClientService $clientService, private AccountToUserService $accountToUserService, private AccountToUserGroupService $accountToUserGroupService ) { diff --git a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php index 138f18e7..37d382e7 100644 --- a/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php +++ b/app/modules/web/Controllers/Helpers/Account/AccountSearchHelper.php @@ -35,7 +35,7 @@ use SP\Domain\Account\Dtos\AccountSearchFilterDto; use SP\Domain\Account\Ports\AccountSearchConstants; use SP\Domain\Account\Ports\AccountSearchService; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -68,21 +68,21 @@ final class AccountSearchHelper extends HelperBase private int $queryTimeStart; private bool $isIndex; private ?AccountSearchFilterDto $accountSearchFilter = null; - private ClientServiceInterface $clientService; + private ClientService $clientService; private AccountSearchService $accountSearchService; private AccountActionsHelper $accountActionsHelper; private CategoryService $categoryService; private TagServiceInterface $tagService; public function __construct( - Application $application, - TemplateInterface $template, - RequestInterface $request, - ClientServiceInterface $clientService, - CategoryService $categoryService, - TagServiceInterface $tagService, - AccountSearchService $accountSearchService, - AccountActionsHelper $accountActionsHelper + Application $application, + TemplateInterface $template, + RequestInterface $request, + ClientService $clientService, + CategoryService $categoryService, + TagServiceInterface $tagService, + AccountSearchService $accountSearchService, + AccountActionsHelper $accountActionsHelper ) { parent::__construct($application, $template, $request); diff --git a/app/modules/web/Controllers/ItemManager/IndexController.php b/app/modules/web/Controllers/ItemManager/IndexController.php index 78f46ecf..eb6e0802 100644 --- a/app/modules/web/Controllers/ItemManager/IndexController.php +++ b/app/modules/web/Controllers/ItemManager/IndexController.php @@ -32,7 +32,7 @@ use SP\Domain\Account\Ports\AccountFileService; use SP\Domain\Account\Ports\AccountHistoryService; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Acl\AclActionsInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -64,7 +64,7 @@ final class IndexController extends ControllerBase private TabsGridHelper $tabsGridHelper; private CategoryService $categoryService; private TagServiceInterface $tagService; - private ClientServiceInterface $clientService; + private ClientService $clientService; private CustomFieldDefServiceInterface $customFieldDefService; private AccountFileService $accountFileService; private AccountService $accountService; @@ -85,7 +85,7 @@ final class IndexController extends ControllerBase Helpers\TabsGridHelper $tabsGridHelper, CategoryService $categoryService, TagServiceInterface $tagService, - ClientServiceInterface $clientService, + ClientService $clientService, CustomFieldDefServiceInterface $customFieldDefService, AccountFileService $accountFileService, AccountService $accountService, diff --git a/app/modules/web/Controllers/Items/ClientsController.php b/app/modules/web/Controllers/Items/ClientsController.php index 9d353f4b..7934d506 100644 --- a/app/modules/web/Controllers/Items/ClientsController.php +++ b/app/modules/web/Controllers/Items/ClientsController.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\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -39,12 +39,12 @@ use SP\Mvc\View\Components\SelectItemAdapter; */ final class ClientsController extends SimpleControllerBase { - private ClientServiceInterface $clientService; + private ClientService $clientService; public function __construct( Application $application, SimpleControllerHelper $simpleControllerHelper, - ClientServiceInterface $clientService + ClientService $clientService ) { parent::__construct($application, $simpleControllerHelper); diff --git a/lib/SP/Domain/Client/Ports/ClientRepositoryInterface.php b/lib/SP/Domain/Client/Ports/ClientRepository.php similarity index 90% rename from lib/SP/Domain/Client/Ports/ClientRepositoryInterface.php rename to lib/SP/Domain/Client/Ports/ClientRepository.php index e44241cf..85528480 100644 --- a/lib/SP/Domain/Client/Ports/ClientRepositoryInterface.php +++ b/lib/SP/Domain/Client/Ports/ClientRepository.php @@ -26,7 +26,7 @@ namespace SP\Domain\Client\Ports; use SP\DataModel\ItemSearchData; use SP\Domain\Account\Ports\AccountFilterBuilder; -use SP\Domain\Client\Models\Client; +use SP\Domain\Client\Models\Client as ClientModel; use SP\Domain\Common\Ports\RepositoryInterface; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; @@ -37,32 +37,32 @@ use SP\Infrastructure\Database\QueryResult; /** * Class ClientRepository * - * @template T of Client + * @template T of ClientModel */ -interface ClientRepositoryInterface extends RepositoryInterface +interface ClientRepository extends RepositoryInterface { /** * Creates an item * - * @param Client $client + * @param ClientModel $client * * @return QueryResult * @throws DuplicatedItemException * @throws SPException */ - public function create(Client $client): QueryResult; + public function create(ClientModel $client): QueryResult; /** * Updates an item * - * @param Client $client + * @param ClientModel $client * * @return int * @throws ConstraintException * @throws QueryException * @throws DuplicatedItemException */ - public function update(Client $client): int; + public function update(ClientModel $client): int; /** * Returns the item for given id diff --git a/lib/SP/Domain/Client/Ports/ClientServiceInterface.php b/lib/SP/Domain/Client/Ports/ClientService.php similarity index 96% rename from lib/SP/Domain/Client/Ports/ClientServiceInterface.php rename to lib/SP/Domain/Client/Ports/ClientService.php index 9612b582..fd369039 100644 --- a/lib/SP/Domain/Client/Ports/ClientServiceInterface.php +++ b/lib/SP/Domain/Client/Ports/ClientService.php @@ -38,7 +38,7 @@ use SP\Infrastructure\Database\QueryResult; /** * Interface ClientServiceInterface */ -interface ClientServiceInterface +interface ClientService { /** * @throws ConstraintException @@ -67,7 +67,7 @@ interface ClientServiceInterface * @throws QueryException * @throws NoSuchItemException */ - public function delete(int $id): ClientServiceInterface; + public function delete(int $id): ClientService; /** * @param int[] $ids diff --git a/lib/SP/Domain/Client/Services/Client.php b/lib/SP/Domain/Client/Services/Client.php index 14f1f0b9..933bf659 100644 --- a/lib/SP/Domain/Client/Services/Client.php +++ b/lib/SP/Domain/Client/Services/Client.php @@ -28,8 +28,8 @@ use SP\Core\Application; use SP\DataModel\ItemSearchData; use SP\Domain\Account\Ports\AccountFilterBuilder; use SP\Domain\Client\Models\Client as ClientModel; -use SP\Domain\Client\Ports\ClientRepositoryInterface; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientRepository; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Common\Models\Simple; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; @@ -47,11 +47,11 @@ use function SP\__u; * * @template T of ClientModel */ -final class Client extends Service implements ClientServiceInterface +final class Client extends Service implements ClientService { public function __construct( - Application $application, - private readonly ClientRepositoryInterface $clientRepository, + Application $application, + private readonly ClientRepository $clientRepository, private readonly AccountFilterBuilder $accountFilterUser ) { parent::__construct($application); @@ -108,12 +108,12 @@ final class Client extends Service implements ClientServiceInterface /** * @param int $id * - * @return ClientServiceInterface + * @return ClientService * @throws ConstraintException * @throws NoSuchItemException * @throws QueryException */ - public function delete(int $id): ClientServiceInterface + public function delete(int $id): ClientService { if ($this->clientRepository->delete($id)->getAffectedNumRows() === 0) { throw new NoSuchItemException(__u('Client not found'), SPException::INFO); diff --git a/lib/SP/Domain/Export/Services/XmlExportService.php b/lib/SP/Domain/Export/Services/XmlExportService.php index ac189eb3..200815df 100644 --- a/lib/SP/Domain/Export/Services/XmlExportService.php +++ b/lib/SP/Domain/Export/Services/XmlExportService.php @@ -38,7 +38,7 @@ use SP\Domain\Account\Ports\AccountService; use SP\Domain\Account\Ports\AccountToTagService; use SP\Domain\Category\Models\Category; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Common\Services\Service; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Config\Ports\ConfigDataInterface; @@ -62,9 +62,9 @@ defined('APP_ROOT') || die(); final class XmlExportService extends Service implements XmlExportServiceInterface { private ConfigDataInterface $configData; - private PhpExtensionChecker $extensionChecker; - private ClientServiceInterface $clientService; - private AccountService $accountService; + private PhpExtensionChecker $extensionChecker; + private ClientService $clientService; + private AccountService $accountService; private AccountToTagService $accountToTagService; private CategoryService $categoryService; private TagServiceInterface $tagService; @@ -76,13 +76,13 @@ final class XmlExportService extends Service implements XmlExportServiceInterfac private ?string $exportFile = null; public function __construct( - Application $application, - PhpExtensionChecker $extensionChecker, - ClientServiceInterface $clientService, - AccountService $accountService, - AccountToTagService $accountToTagService, - CategoryService $categoryService, - TagServiceInterface $tagService + Application $application, + PhpExtensionChecker $extensionChecker, + ClientService $clientService, + AccountService $accountService, + AccountToTagService $accountToTagService, + CategoryService $categoryService, + TagServiceInterface $tagService ) { parent::__construct($application); diff --git a/lib/SP/Domain/Import/Services/ImportHelper.php b/lib/SP/Domain/Import/Services/ImportHelper.php index 842bcd39..71eadb40 100644 --- a/lib/SP/Domain/Import/Services/ImportHelper.php +++ b/lib/SP/Domain/Import/Services/ImportHelper.php @@ -27,7 +27,7 @@ namespace SP\Domain\Import\Services; use SP\Domain\Account\Ports\AccountService; use SP\Domain\Category\Ports\CategoryService; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Tag\Ports\TagServiceInterface; /** @@ -36,15 +36,15 @@ use SP\Domain\Tag\Ports\TagServiceInterface; final class ImportHelper { private AccountService $accountService; - private CategoryService $categoryService; - private ClientServiceInterface $clientService; - private TagServiceInterface $tagService; + private CategoryService $categoryService; + private ClientService $clientService; + private TagServiceInterface $tagService; public function __construct( - AccountService $accountService, - CategoryService $categoryService, - ClientServiceInterface $clientService, - TagServiceInterface $tagService + AccountService $accountService, + CategoryService $categoryService, + ClientService $clientService, + TagServiceInterface $tagService ) { $this->accountService = $accountService; $this->categoryService = $categoryService; @@ -62,7 +62,7 @@ final class ImportHelper return $this->categoryService; } - public function getClientService(): ClientServiceInterface + public function getClientService(): ClientService { return $this->clientService; } diff --git a/lib/SP/Domain/Import/Services/ImportTrait.php b/lib/SP/Domain/Import/Services/ImportTrait.php index 8af3efd7..daae1213 100644 --- a/lib/SP/Domain/Import/Services/ImportTrait.php +++ b/lib/SP/Domain/Import/Services/ImportTrait.php @@ -32,7 +32,7 @@ use SP\Domain\Account\Ports\AccountService; use SP\Domain\Category\Models\Category; use SP\Domain\Category\Ports\CategoryService; use SP\Domain\Client\Models\Client; -use SP\Domain\Client\Ports\ClientServiceInterface; +use SP\Domain\Client\Ports\ClientService; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\NoSuchPropertyException; use SP\Domain\Core\Exceptions\QueryException; @@ -55,9 +55,9 @@ trait ImportTrait protected int $counter = 0; protected ImportParams $importParams; private AccountService $accountService; - private CategoryService $categoryService; - private ClientServiceInterface $clientService; - private TagServiceInterface $tagService; + private CategoryService $categoryService; + private ClientService $clientService; + private TagServiceInterface $tagService; private array $items; /** diff --git a/lib/SP/Infrastructure/Client/Repositories/ClientRepository.php b/lib/SP/Infrastructure/Client/Repositories/Client.php similarity index 89% rename from lib/SP/Infrastructure/Client/Repositories/ClientRepository.php rename to lib/SP/Infrastructure/Client/Repositories/Client.php index dede1371..f4edfcad 100644 --- a/lib/SP/Infrastructure/Client/Repositories/ClientRepository.php +++ b/lib/SP/Infrastructure/Client/Repositories/Client.php @@ -26,8 +26,8 @@ namespace SP\Infrastructure\Client\Repositories; use SP\DataModel\ItemSearchData; use SP\Domain\Account\Ports\AccountFilterBuilder; -use SP\Domain\Client\Models\Client; -use SP\Domain\Client\Ports\ClientRepositoryInterface; +use SP\Domain\Client\Models\Client as ClientModel; +use SP\Domain\Client\Ports\ClientRepository; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; @@ -42,9 +42,9 @@ use function SP\__u; /** * Class ClientRepository * - * @template T of Client + * @template T of ClientModel */ -final class ClientRepository extends Repository implements ClientRepositoryInterface +final class Client extends Repository implements ClientRepository { use RepositoryItemTrait; @@ -53,13 +53,13 @@ final class ClientRepository extends Repository implements ClientRepositoryInter /** * Creates an item * - * @param Client $client + * @param ClientModel $client * * @return QueryResult * @throws DuplicatedItemException * @throws SPException */ - public function create(Client $client): QueryResult + public function create(ClientModel $client): QueryResult { if ($this->checkDuplicatedOnAdd($client)) { throw new DuplicatedItemException(__u('Duplicated client')); @@ -79,12 +79,12 @@ final class ClientRepository extends Repository implements ClientRepositoryInter /** * Checks whether the item is duplicated on adding * - * @param Client $client + * @param ClientModel $client * @return bool * @throws ConstraintException * @throws QueryException */ - private function checkDuplicatedOnAdd(Client $client): bool + private function checkDuplicatedOnAdd(ClientModel $client): bool { $query = $this->queryFactory ->newSelect() @@ -105,14 +105,14 @@ final class ClientRepository extends Repository implements ClientRepositoryInter /** * Updates an item * - * @param Client $client + * @param ClientModel $client * * @return int * @throws ConstraintException * @throws QueryException * @throws DuplicatedItemException */ - public function update(Client $client): int + public function update(ClientModel $client): int { if ($this->checkDuplicatedOnUpdate($client)) { throw new DuplicatedItemException(__u('Duplicated client')); @@ -139,13 +139,13 @@ final class ClientRepository extends Repository implements ClientRepositoryInter /** * Checks whether the item is duplicated on updating * - * @param Client $client + * @param ClientModel $client * * @return bool * @throws ConstraintException * @throws QueryException */ - private function checkDuplicatedOnUpdate(Client $client): bool + private function checkDuplicatedOnUpdate(ClientModel $client): bool { $query = $this->queryFactory ->newSelect() @@ -176,12 +176,12 @@ final class ClientRepository extends Repository implements ClientRepositoryInter $query = $this->queryFactory ->newSelect() ->from(self::TABLE) - ->cols(Client::getCols()) + ->cols(ClientModel::getCols()) ->where('id = :id') ->bindValues(['id' => $clientId]) ->limit(1); - $queryData = QueryData::buildWithMapper($query, Client::class); + $queryData = QueryData::buildWithMapper($query, ClientModel::class); return $this->db->doSelect($queryData); } @@ -198,12 +198,12 @@ final class ClientRepository extends Repository implements ClientRepositoryInter $query = $this->queryFactory ->newSelect() ->from(self::TABLE) - ->cols(Client::getCols()) + ->cols(ClientModel::getCols()) ->where('(name = :name OR hash = :hash)') ->bindValues(['name' => $name, 'hash' => $this->makeItemHash($name)]) ->limit(1); - $queryData = QueryData::buildWithMapper($query, Client::class); + $queryData = QueryData::buildWithMapper($query, ClientModel::class); return $this->db->doSelect($queryData); } @@ -218,9 +218,9 @@ final class ClientRepository extends Repository implements ClientRepositoryInter $query = $this->queryFactory ->newSelect() ->from(self::TABLE) - ->cols(Client::getCols()); + ->cols(ClientModel::getCols()); - return $this->db->doSelect(QueryData::buildWithMapper($query, Client::class)); + return $this->db->doSelect(QueryData::buildWithMapper($query, ClientModel::class)); } /** @@ -282,7 +282,7 @@ final class ClientRepository extends Repository implements ClientRepositoryInter $query = $this->queryFactory ->newSelect() ->from(self::TABLE) - ->cols(Client::getCols(['hash'])) + ->cols(ClientModel::getCols(['hash'])) ->orderBy(['name']) ->limit($itemSearchData->getLimitCount()) ->offset($itemSearchData->getLimitStart()); @@ -295,7 +295,7 @@ final class ClientRepository extends Repository implements ClientRepositoryInter $query->bindValues(['name' => $search, 'description' => $search]); } - $queryData = QueryData::build($query)->setMapClassName(Client::class); + $queryData = QueryData::build($query)->setMapClassName(ClientModel::class); return $this->db->doSelect($queryData, true); } diff --git a/tests/SPT/Domain/Client/Services/ClientTest.php b/tests/SPT/Domain/Client/Services/ClientTest.php index 4bcc2cb5..ed2a1c48 100644 --- a/tests/SPT/Domain/Client/Services/ClientTest.php +++ b/tests/SPT/Domain/Client/Services/ClientTest.php @@ -29,7 +29,7 @@ use Exception; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\Stub; use SP\Domain\Account\Ports\AccountFilterBuilder; -use SP\Domain\Client\Ports\ClientRepositoryInterface; +use SP\Domain\Client\Ports\ClientRepository; use SP\Domain\Client\Services\Client; use SP\Domain\Common\Services\ServiceException; use SP\Domain\Core\Exceptions\ConstraintException; @@ -50,9 +50,9 @@ use SPT\UnitaryTestCase; class ClientTest extends UnitaryTestCase { - private ClientRepositoryInterface|MockObject $clientRepository; - private Client $clientService; - private AccountFilterBuilder|Stub $accountFilterUser; + private ClientRepository|MockObject $clientRepository; + private Client $client; + private AccountFilterBuilder|Stub $accountFilterUser; /** * @throws NoSuchItemException @@ -72,7 +72,7 @@ class ClientTest extends UnitaryTestCase ->with($id) ->willReturn(new QueryResult([$client])); - $out = $this->clientService->getById($id); + $out = $this->client->getById($id); $this->assertEquals($client, $out); } @@ -96,7 +96,7 @@ class ClientTest extends UnitaryTestCase $this->expectException(NoSuchItemException::class); $this->expectExceptionMessage('Client not found'); - $this->clientService->getById($id); + $this->client->getById($id); } /** @@ -111,7 +111,7 @@ class ClientTest extends UnitaryTestCase ->method('search') ->with($itemSearch); - $this->clientService->search($itemSearch); + $this->client->search($itemSearch); } /** @@ -132,7 +132,7 @@ class ClientTest extends UnitaryTestCase ->with($id) ->willReturn($queryResult); - $this->clientService->delete($id); + $this->client->delete($id); } /** @@ -152,7 +152,7 @@ class ClientTest extends UnitaryTestCase $this->expectException(NoSuchItemException::class); $this->expectExceptionMessage('Client not found'); - $this->clientService->delete($id); + $this->client->delete($id); } /** @@ -172,7 +172,7 @@ class ClientTest extends UnitaryTestCase ->with($client) ->willReturn($queryResult); - $out = $this->clientService->create($client); + $out = $this->client->create($client); $this->assertEquals($queryResult->getLastId(), $out); } @@ -195,7 +195,7 @@ class ClientTest extends UnitaryTestCase ->with($client) ->willReturn(1); - $this->clientService->update($client); + $this->client->update($client); } /** @@ -216,7 +216,7 @@ class ClientTest extends UnitaryTestCase ->with($name) ->willReturn(new QueryResult([$client])); - $out = $this->clientService->getByName($name); + $out = $this->client->getByName($name); $this->assertEquals($client, $out); } @@ -240,7 +240,7 @@ class ClientTest extends UnitaryTestCase $this->expectException(NoSuchItemException::class); $this->expectExceptionMessage('Client not found'); - $this->clientService->getByName($name); + $this->client->getByName($name); } /** @@ -261,7 +261,7 @@ class ClientTest extends UnitaryTestCase ->with($ids) ->willReturn($queryResult); - $this->clientService->deleteByIdBatch($ids); + $this->client->deleteByIdBatch($ids); } /** @@ -284,7 +284,7 @@ class ClientTest extends UnitaryTestCase $this->expectException(ServiceException::class); $this->expectExceptionMessage('Error while deleting the clients'); - $this->clientService->deleteByIdBatch($ids); + $this->client->deleteByIdBatch($ids); } /** @@ -301,7 +301,7 @@ class ClientTest extends UnitaryTestCase ->method('getAll') ->willReturn(new QueryResult([$client])); - $out = $this->clientService->getAll(); + $out = $this->client->getAll(); $this->assertEquals([$client], $out); } @@ -321,7 +321,7 @@ class ClientTest extends UnitaryTestCase ->with($this->accountFilterUser) ->willReturn(new QueryResult([$client])); - $out = $this->clientService->getAllForUser(); + $out = $this->client->getAllForUser(); $this->assertEquals([$client], $out); } @@ -330,7 +330,7 @@ class ClientTest extends UnitaryTestCase { parent::setUp(); - $this->clientRepository = $this->createMock(ClientRepositoryInterface::class); + $this->clientRepository = $this->createMock(ClientRepository::class); $select = (new QueryFactory('mysql', QueryFactory::COMMON))->newSelect(); @@ -338,6 +338,6 @@ class ClientTest extends UnitaryTestCase $this->accountFilterUser->method('buildFilter') ->willReturn($select); - $this->clientService = new Client($this->application, $this->clientRepository, $this->accountFilterUser); + $this->client = new Client($this->application, $this->clientRepository, $this->accountFilterUser); } } diff --git a/tests/SPT/Infrastructure/Client/Repositories/ClientRepositoryTest.php b/tests/SPT/Infrastructure/Client/Repositories/ClientTest.php similarity index 91% rename from tests/SPT/Infrastructure/Client/Repositories/ClientRepositoryTest.php rename to tests/SPT/Infrastructure/Client/Repositories/ClientTest.php index 9e9a4022..a026f4be 100644 --- a/tests/SPT/Infrastructure/Client/Repositories/ClientRepositoryTest.php +++ b/tests/SPT/Infrastructure/Client/Repositories/ClientTest.php @@ -34,12 +34,12 @@ use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; use SP\DataModel\ItemSearchData; use SP\Domain\Account\Ports\AccountFilterBuilder; -use SP\Domain\Client\Models\Client; +use SP\Domain\Client\Models\Client as ClientModel; use SP\Domain\Common\Models\Simple; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; -use SP\Infrastructure\Client\Repositories\ClientRepository; +use SP\Infrastructure\Client\Repositories\Client; use SP\Infrastructure\Common\Repositories\DuplicatedItemException; use SP\Infrastructure\Database\DatabaseInterface; use SP\Infrastructure\Database\QueryData; @@ -52,10 +52,10 @@ use SPT\UnitaryTestCase; * * @group unitary */ -class ClientRepositoryTest extends UnitaryTestCase +class ClientTest extends UnitaryTestCase { - private ClientRepository $clientRepository; + private Client $client; private DatabaseInterface|MockObject $database; /** @@ -102,7 +102,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->with(...self::withConsecutive([$callbackDuplicate], [$callbackCreate])) ->willReturn(new QueryResult([]), new QueryResult([1])); - $this->clientRepository->create($client); + $this->client->create($client); } /** @@ -135,7 +135,7 @@ class ClientRepositoryTest extends UnitaryTestCase $this->expectException(DuplicatedItemException::class); $this->expectExceptionMessage('Duplicated client'); - $this->clientRepository->create($client); + $this->client->create($client); } /** @@ -158,7 +158,7 @@ class ClientRepositoryTest extends UnitaryTestCase $this->database->expects(self::once())->method('doQuery')->with($callback); - $this->clientRepository->delete($id); + $this->client->delete($id); } /** @@ -189,7 +189,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->method('doQuery') ->with($callback); - $this->clientRepository->deleteByIdBatch($ids); + $this->client->deleteByIdBatch($ids); } /** @@ -202,7 +202,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->expects(self::never()) ->method('doQuery'); - $this->clientRepository->deleteByIdBatch([]); + $this->client->deleteByIdBatch([]); } public function testGetById() @@ -216,7 +216,7 @@ class ClientRepositoryTest extends UnitaryTestCase return count($params) === 1 && $params['id'] === $id - && $arg->getMapClassName() === Client::class + && $arg->getMapClassName() === ClientModel::class && is_a($query, SelectInterface::class) && !empty($query->getStatement()); } @@ -227,7 +227,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->method('doSelect') ->with($callback); - $this->clientRepository->getById($id); + $this->client->getById($id); } /** @@ -246,7 +246,7 @@ class ClientRepositoryTest extends UnitaryTestCase return count($params) === 2 && $params['name'] === $searchStringLike && $params['description'] === $searchStringLike - && $arg->getMapClassName() === Client::class + && $arg->getMapClassName() === ClientModel::class && is_a($query, SelectInterface::class) && !empty($query->getStatement()); } @@ -257,7 +257,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->method('doSelect') ->with($callback, true); - $this->clientRepository->search($item); + $this->client->search($item); } /** @@ -269,7 +269,7 @@ class ClientRepositoryTest extends UnitaryTestCase static function (QueryData $arg) { $query = $arg->getQuery(); return count($query->getBindValues()) === 0 - && $arg->getMapClassName() === Client::class + && $arg->getMapClassName() === ClientModel::class && is_a($query, SelectInterface::class) && !empty($query->getStatement()); } @@ -280,7 +280,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->method('doSelect') ->with($callback, true); - $this->clientRepository->search(new ItemSearchData()); + $this->client->search(new ItemSearchData()); } public function testGetAll() @@ -288,7 +288,7 @@ class ClientRepositoryTest extends UnitaryTestCase $callback = new Callback( static function (QueryData $arg) { $query = $arg->getQuery(); - return $arg->getMapClassName() === Client::class + return $arg->getMapClassName() === ClientModel::class && is_a($query, SelectInterface::class) && !empty($query->getStatement()); } @@ -299,7 +299,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->method('doSelect') ->with($callback); - $this->clientRepository->getAll(); + $this->client->getAll(); } /** @@ -328,7 +328,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->method('buildFilter') ->willReturn($select); - $this->clientRepository->getAllForFilter($accountFilterUser); + $this->client->getAllForFilter($accountFilterUser); } /** @@ -376,7 +376,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->with(...self::withConsecutive([$callbackDuplicate], [$callbackUpdate])) ->willReturn(new QueryResult([]), new QueryResult([1])); - $this->clientRepository->update($client); + $this->client->update($client); } /** @@ -410,7 +410,7 @@ class ClientRepositoryTest extends UnitaryTestCase $this->expectException(DuplicatedItemException::class); $this->expectExceptionMessage('Duplicated client'); - $this->clientRepository->update($client); + $this->client->update($client); } public function testGetByName() @@ -425,7 +425,7 @@ class ClientRepositoryTest extends UnitaryTestCase return count($params) === 2 && $params['name'] === $name && !empty($params['hash']) - && $arg->getMapClassName() === Client::class + && $arg->getMapClassName() === ClientModel::class && is_a($query, SelectInterface::class) && !empty($query->getStatement()); } @@ -436,7 +436,7 @@ class ClientRepositoryTest extends UnitaryTestCase ->method('doSelect') ->with($callback); - $this->clientRepository->getByName($name); + $this->client->getByName($name); } protected function setUp(): void @@ -446,7 +446,7 @@ class ClientRepositoryTest extends UnitaryTestCase $this->database = $this->createMock(DatabaseInterface::class); $queryFactory = new QueryFactory('mysql'); - $this->clientRepository = new ClientRepository( + $this->client = new Client( $this->database, $this->context, $this->application->getEventDispatcher(),