From ff9bf9f91d9b263cdb0e071e4b6a5d75b66240ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20D?= Date: Sat, 9 Mar 2024 13:16:47 +0100 Subject: [PATCH] chore: Remove unneeded classes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rubén D --- lib/SP/DataModel/AccountSearchVData.php | 210 ----------------- lib/SP/DataModel/AccountToUserGroupData.php | 106 --------- lib/SP/DataModel/AccountVData.php | 222 ------------------ .../Account/Dtos/AccountSearchFilterDto.php | 3 +- .../Account/Repositories/AccountSearch.php | 12 +- lib/SP/Mvc/Model/QueryCondition.php | 81 ------- .../Repositories/AccountSearchTest.php | 8 +- 7 files changed, 11 insertions(+), 631 deletions(-) delete mode 100644 lib/SP/DataModel/AccountSearchVData.php delete mode 100644 lib/SP/DataModel/AccountToUserGroupData.php delete mode 100644 lib/SP/DataModel/AccountVData.php delete mode 100644 lib/SP/Mvc/Model/QueryCondition.php diff --git a/lib/SP/DataModel/AccountSearchVData.php b/lib/SP/DataModel/AccountSearchVData.php deleted file mode 100644 index f5ac1183..00000000 --- a/lib/SP/DataModel/AccountSearchVData.php +++ /dev/null @@ -1,210 +0,0 @@ -. - */ - -namespace SP\DataModel; - -use SP\Domain\Common\Models\Model; - -/** - * Class AccountSearchData - * - * @package SP\DataModel - */ -class AccountSearchVData extends Model -{ - public ?string $publicLinkHash = null; - protected ?int $id = 0; - protected ?string $name = ''; - protected ?int $clientId = 0; - protected ?string $clientName = null; - protected ?int $categoryId = null; - protected ?string $categoryName = null; - protected ?int $userId = 0; - protected ?string $userName = null; - protected ?string $userLogin = null; - protected ?int $userGroupId = 0; - protected ?string $userGroupName = null; - protected ?int $userEditId = 0; - protected ?string $userEditName = null; - protected ?string $userEditLogin = null; - protected ?string $login = null; - protected ?string $url = null; - protected ?string $notes = null; - protected ?int $otherUserEdit = null; - protected ?int $otherUserGroupEdit = null; - protected ?int $dateEdit = null; - protected ?int $isPrivate = null; - protected ?int $isPrivateGroup = null; - protected ?int $passDate = null; - protected ?int $passDateChange = null; - protected ?int $parentId = null; - protected ?int $num_files = null; - protected ?int $publicLinkDateExpire = null; - protected ?int $publicLinkTotalCountViews = null; - - public function getPublicLinkHash(): ?string - { - return $this->publicLinkHash; - } - - public function getId(): ?int - { - return $this->id; - } - - public function getUserId(): ?int - { - return $this->userId; - } - - public function getUserGroupId(): ?int - { - return $this->userGroupId; - } - - public function getUserEditId(): ?int - { - return $this->userEditId; - } - - public function getName(): ?string - { - return $this->name; - } - - public function getClientId(): ?int - { - return $this->clientId; - } - - public function getCategoryId(): ?int - { - return $this->categoryId; - } - - public function getLogin(): ?string - { - return $this->login; - } - - public function getUrl(): ?string - { - return $this->url; - } - - public function getNotes(): ?string - { - return $this->notes; - } - - public function getOtherUserEdit(): ?int - { - return $this->otherUserEdit; - } - - public function getOtherUserGroupEdit(): ?int - { - return $this->otherUserGroupEdit; - } - - public function getIsPrivate(): ?int - { - return $this->isPrivate; - } - - public function getIsPrivateGroup(): ?int - { - return $this->isPrivateGroup; - } - - public function getDateEdit(): ?int - { - return $this->dateEdit; - } - - public function getPassDate(): ?int - { - return $this->passDate; - } - - public function getPassDateChange(): ?int - { - return $this->passDateChange; - } - - public function getParentId(): ?int - { - return $this->parentId; - } - - public function getCategoryName(): ?string - { - return $this->categoryName; - } - - public function getClientName(): ?string - { - return $this->clientName; - } - - public function getUserGroupName(): ?string - { - return $this->userGroupName; - } - - public function getUserName(): ?string - { - return $this->userName; - } - - public function getUserLogin(): ?string - { - return $this->userLogin; - } - - public function getUserEditName(): ?string - { - return $this->userEditName; - } - - public function getUserEditLogin(): ?string - { - return $this->userEditLogin; - } - - public function getNumFiles(): ?int - { - return $this->num_files; - } - - public function getPublicLinkDateExpire(): ?int - { - return $this->publicLinkDateExpire; - } - - public function getPublicLinkTotalCountViews(): ?int - { - return $this->publicLinkTotalCountViews; - } -} diff --git a/lib/SP/DataModel/AccountToUserGroupData.php b/lib/SP/DataModel/AccountToUserGroupData.php deleted file mode 100644 index f938eb08..00000000 --- a/lib/SP/DataModel/AccountToUserGroupData.php +++ /dev/null @@ -1,106 +0,0 @@ -. - */ - -namespace SP\DataModel; - -use SP\Domain\Common\Models\Model; - -defined('APP_ROOT') || die(); - -/** - * Class GroupAccountsData - * - * @package SP\DataModel - */ -class AccountToUserGroupData extends Model -{ - /** - * @var int - */ - public $userGroupId = 0; - /** - * @var int - */ - public $accountId = 0; - /** - * @var array - */ - protected $groups = []; - - /** - * @return int - */ - public function getUserGroupId() - { - return $this->userGroupId; - } - - /** - * @param int $userGroupId - */ - public function setUserGroupId($userGroupId) - { - $this->userGroupId = $userGroupId; - } - - /** - * @return int - */ - public function getAccountId() - { - return $this->accountId; - } - - /** - * @param int $accountId - */ - public function setAccountId($accountId) - { - $this->accountId = $accountId; - } - - /** - * @return array - */ - public function getGroups() - { - return $this->groups; - } - - /** - * @param array $groups - */ - public function setGroups(array $groups) - { - $this->groups = $groups; - } - - /** - * @param int $group - */ - public function addGroup($group) - { - $this->groups[] = (int)$group; - } -} diff --git a/lib/SP/DataModel/AccountVData.php b/lib/SP/DataModel/AccountVData.php deleted file mode 100644 index d68d349a..00000000 --- a/lib/SP/DataModel/AccountVData.php +++ /dev/null @@ -1,222 +0,0 @@ -. - */ - -namespace SP\DataModel; - -use SP\Domain\Common\Models\Model; - -/** - * Class AccountVData - * - * @package SP\DataModel - */ -class AccountVData extends Model -{ - protected ?int $id = null; - protected ?int $userId = null; - protected ?int $userGroupId = null; - protected ?int $userEditId = null; - protected ?string $name = null; - protected ?int $clientId = null; - protected ?int $categoryId = null; - protected ?string $login = null; - protected ?string $url = null; - protected ?string $pass = null; - protected ?string $key = null; - protected ?string $notes = null; - protected ?int $otherUserEdit = null; - protected ?int $otherUserGroupEdit = null; - protected ?int $dateAdd = null; - protected ?int $dateEdit = null; - protected ?int $countView = null; - protected ?int $countDecrypt = null; - protected ?int $isPrivate = null; - protected ?int $isPrivateGroup = null; - protected ?int $passDate = null; - protected ?int $passDateChange = null; - protected ?int $parentId = null; - protected ?string $categoryName = null; - protected ?string $clientName = null; - protected ?string $userGroupName = null; - protected ?string $userName = null; - protected ?string $userLogin = null; - protected ?string $userEditName = null; - protected ?string $userEditLogin = null; - protected ?string $publicLinkHash = null; - - public function getId(): ?int - { - return $this->id; - } - - public function getUserId(): ?int - { - return $this->userId; - } - - public function getUserGroupId(): ?int - { - return $this->userGroupId; - } - - public function getUserEditId(): ?int - { - return $this->userEditId; - } - - public function getName(): ?string - { - return $this->name; - } - - public function getClientId(): ?int - { - return $this->clientId; - } - - public function getCategoryId(): ?int - { - return $this->categoryId; - } - - public function getLogin(): ?string - { - return $this->login; - } - - public function getUrl(): ?string - { - return $this->url; - } - - public function getPass(): ?string - { - return $this->pass; - } - - public function getKey(): ?string - { - return $this->key; - } - - public function getNotes(): ?string - { - return $this->notes; - } - - public function getOtherUserEdit(): ?int - { - return $this->otherUserEdit; - } - - public function getOtherUserGroupEdit(): ?int - { - return $this->otherUserGroupEdit; - } - - public function getDateAdd(): ?int - { - return $this->dateAdd; - } - - public function getDateEdit(): ?int - { - return $this->dateEdit; - } - - public function getCountView(): ?int - { - return $this->countView; - } - - public function getCountDecrypt(): ?int - { - return $this->countDecrypt; - } - - public function getIsPrivate(): ?int - { - return $this->isPrivate; - } - - public function getIsPrivateGroup(): ?int - { - return $this->isPrivateGroup; - } - - public function getPassDate(): ?int - { - return $this->passDate; - } - - public function getPassDateChange(): ?int - { - return $this->passDateChange; - } - - public function getParentId(): ?int - { - return $this->parentId; - } - - public function getCategoryName(): ?string - { - return $this->categoryName; - } - - public function getClientName(): ?string - { - return $this->clientName; - } - - public function getUserGroupName(): ?string - { - return $this->userGroupName; - } - - public function getUserName(): ?string - { - return $this->userName; - } - - public function getUserLogin(): ?string - { - return $this->userLogin; - } - - public function getUserEditName(): ?string - { - return $this->userEditName; - } - - public function getUserEditLogin(): ?string - { - return $this->userEditLogin; - } - - public function getPublicLinkHash(): ?string - { - return $this->publicLinkHash; - } -} diff --git a/lib/SP/Domain/Account/Dtos/AccountSearchFilterDto.php b/lib/SP/Domain/Account/Dtos/AccountSearchFilterDto.php index de819834..c0d555e3 100644 --- a/lib/SP/Domain/Account/Dtos/AccountSearchFilterDto.php +++ b/lib/SP/Domain/Account/Dtos/AccountSearchFilterDto.php @@ -25,7 +25,6 @@ namespace SP\Domain\Account\Dtos; use SP\Domain\Account\Ports\AccountSearchConstants; -use SP\Mvc\Model\QueryCondition; /** * Class AccountSearchFilter @@ -214,7 +213,7 @@ final class AccountSearchFilterDto public function getFilterOperator(): string { - return $this->filterOperator ?? QueryCondition::CONDITION_AND; + return $this->filterOperator ?? AccountSearchConstants::FILTER_CHAIN_AND; } public function setFilterOperator(?string $filterOperator): void diff --git a/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php b/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php index 395bbbc0..bdc22208 100644 --- a/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php +++ b/lib/SP/Infrastructure/Account/Repositories/AccountSearch.php @@ -26,8 +26,8 @@ namespace SP\Infrastructure\Account\Repositories; use Aura\SqlQuery\Common\SelectInterface; use Aura\SqlQuery\QueryFactory; -use SP\DataModel\AccountSearchVData; use SP\Domain\Account\Dtos\AccountSearchFilterDto; +use SP\Domain\Account\Models\AccountSearchView; use SP\Domain\Account\Ports\AccountFilterBuilder; use SP\Domain\Account\Ports\AccountSearchConstants; use SP\Domain\Account\Ports\AccountSearchRepository; @@ -47,10 +47,10 @@ final class AccountSearch extends BaseRepository implements AccountSearchReposit private readonly SelectInterface $query; public function __construct( - DatabaseInterface $database, - ContextInterface $session, - EventDispatcherInterface $eventDispatcher, - QueryFactory $queryFactory, + DatabaseInterface $database, + ContextInterface $session, + EventDispatcherInterface $eventDispatcher, + QueryFactory $queryFactory, private readonly AccountFilterBuilder $accountFilterUser ) { parent::__construct($database, $session, $eventDispatcher, $queryFactory); @@ -118,7 +118,7 @@ final class AccountSearch extends BaseRepository implements AccountSearchReposit } return $this->db->doSelect( - QueryData::build($this->query)->setMapClassName(AccountSearchVData::class), + QueryData::build($this->query)->setMapClassName(AccountSearchView::class), true ); } diff --git a/lib/SP/Mvc/Model/QueryCondition.php b/lib/SP/Mvc/Model/QueryCondition.php deleted file mode 100644 index d7fdec48..00000000 --- a/lib/SP/Mvc/Model/QueryCondition.php +++ /dev/null @@ -1,81 +0,0 @@ -. - */ - -namespace SP\Mvc\Model; - -use RuntimeException; - -/** - * Class QueryCondition - * - * @package SP\Mvc\Model - */ -final class QueryCondition -{ - public const CONDITION_AND = ' AND '; - public const CONDITION_OR = ' OR '; - - protected array $query = []; - protected array $param = []; - - public function addFilter( - string $query, - ?array $params = null - ): QueryCondition - { - $this->query[] = "($query)"; - - if ($params !== null) { - $this->param = array_merge($this->param, $params); - } - - return $this; - } - - public function getFilters(string $type = self::CONDITION_AND): ?string - { - if ($type !== self::CONDITION_AND && $type !== self::CONDITION_OR) { - throw new RuntimeException(__u('Invalid filter type')); - } - - return $this->hasFilters() - ? '(' . implode($type, $this->query) . ')' - : null; - } - - public function hasFilters(): bool - { - return count($this->query) !== 0; - } - - public function getParams(): array - { - return $this->param; - } - - public function getFiltersCount(): int - { - return count($this->query); - } -} \ No newline at end of file diff --git a/tests/SPT/Infrastructure/Account/Repositories/AccountSearchTest.php b/tests/SPT/Infrastructure/Account/Repositories/AccountSearchTest.php index b1dee5f8..2f649ec6 100644 --- a/tests/SPT/Infrastructure/Account/Repositories/AccountSearchTest.php +++ b/tests/SPT/Infrastructure/Account/Repositories/AccountSearchTest.php @@ -22,13 +22,13 @@ * along with sysPass. If not, see . */ -namespace Infrastructure\Account\Repositories; +namespace SPT\Infrastructure\Account\Repositories; use Aura\SqlQuery\QueryFactory; use PHPUnit\Framework\Constraint\Callback; use PHPUnit\Framework\MockObject\MockObject; -use SP\DataModel\AccountSearchVData; use SP\Domain\Account\Dtos\AccountSearchFilterDto; +use SP\Domain\Account\Models\AccountSearchView; use SP\Domain\Account\Ports\AccountFilterBuilder; use SP\Domain\Account\Ports\AccountSearchConstants; use SP\Infrastructure\Account\Repositories\AccountSearch; @@ -192,7 +192,7 @@ class AccountSearchTest extends UnitaryTestCase ->with( new Callback(static function (QueryData $data) { return !empty($data->getQuery()->getStatement()) && - $data->getMapClassName() === AccountSearchVData::class; + $data->getMapClassName() === AccountSearchView::class; }), true ); @@ -213,7 +213,7 @@ class AccountSearchTest extends UnitaryTestCase ->with( new Callback(static function (QueryData $data) { return !empty($data->getQuery()->getStatement()) && - $data->getMapClassName() === AccountSearchVData::class; + $data->getMapClassName() === AccountSearchView::class; }), true );