From 0e9e09129472fbefc963f0a34053675b987529c2 Mon Sep 17 00:00:00 2001 From: mesilov Date: Mon, 22 Jul 2024 01:14:26 +0600 Subject: [PATCH] Refactor code for improved readability and consistency A variety of changes have been made across several files to enhance readability and optimize semantics. This includes implementing the Stringable interface in the FullName class and cleaning up variable names to be more descriptive. Additionally, unnecessary comments have been removed and elements in the Scope class are now transformed to lowercase in a more concise way. Signed-off-by: mesilov --- .../Bitrix24AccountRepositoryInterface.php | 5 ++--- .../ContactPersons/Entity/ContactPersonInterface.php | 12 ++---------- .../Contracts/ContactPersons/Entity/FullName.php | 7 +++++-- .../Repository/ContactPersonRepositoryInterface.php | 10 ++-------- src/Core/Batch.php | 10 +++++----- src/Core/Credentials/Scope.php | 2 +- 6 files changed, 17 insertions(+), 29 deletions(-) diff --git a/src/Application/Contracts/Bitrix24Accounts/Repository/Bitrix24AccountRepositoryInterface.php b/src/Application/Contracts/Bitrix24Accounts/Repository/Bitrix24AccountRepositoryInterface.php index 7ba5c82f..e0d01d56 100644 --- a/src/Application/Contracts/Bitrix24Accounts/Repository/Bitrix24AccountRepositoryInterface.php +++ b/src/Application/Contracts/Bitrix24Accounts/Repository/Bitrix24AccountRepositoryInterface.php @@ -34,7 +34,6 @@ public function getById(Uuid $uuid): Bitrix24AccountInterface; /** * Find one admin bitrix24 account by member_id * @param non-empty-string $memberId - * @return Bitrix24AccountInterface|null */ public function findOneAdminByMemberId(string $memberId): ?Bitrix24AccountInterface; @@ -43,12 +42,12 @@ public function findOneAdminByMemberId(string $memberId): ?Bitrix24AccountInterf * @param non-empty-string $memberId * @return Bitrix24AccountInterface[] */ - public function findByMemberId(string $memberId, ?Bitrix24AccountStatus $status = null, ?bool $isAdmin = null): array; + public function findByMemberId(string $memberId, ?Bitrix24AccountStatus $bitrix24AccountStatus = null, ?bool $isAdmin = null): array; /** * Find bitrix24 accounts by domain url and filter by status adn isAdmin flag * @param non-empty-string $domainUrl * @return Bitrix24AccountInterface[] */ - public function findByDomain(string $domainUrl, ?Bitrix24AccountStatus $status = null, ?bool $isAdmin = null): array; + public function findByDomain(string $domainUrl, ?Bitrix24AccountStatus $bitrix24AccountStatus = null, ?bool $isAdmin = null): array; } \ No newline at end of file diff --git a/src/Application/Contracts/ContactPersons/Entity/ContactPersonInterface.php b/src/Application/Contracts/ContactPersons/Entity/ContactPersonInterface.php index 0392e430..03b45af6 100644 --- a/src/Application/Contracts/ContactPersons/Entity/ContactPersonInterface.php +++ b/src/Application/Contracts/ContactPersons/Entity/ContactPersonInterface.php @@ -42,6 +42,7 @@ public function markAsBlocked(?string $comment): void; * @throws InvalidArgumentException */ public function markAsDeleted(?string $comment): void; + /** * @return FullName return contact person full name */ @@ -64,11 +65,6 @@ public function getUpdatedAt(): CarbonImmutable; */ public function getEmail(): ?string; - /** - * @param string|null $email - * @param bool|null $isEmailVerified - * @return void - */ public function changeEmail(?string $email, ?bool $isEmailVerified = null): void; /** @@ -83,12 +79,8 @@ public function getEmailVerifiedAt(): ?CarbonImmutable; /** * Change mobile phone for contact person - * - * @param PhoneNumber|null $mobilePhone - * @param bool|null $isMobilePhoneVerified - * @return void */ - public function changeMobilePhone(?PhoneNumber $mobilePhone, ?bool $isMobilePhoneVerified = null): void; + public function changeMobilePhone(?PhoneNumber $phoneNumber, ?bool $isMobilePhoneVerified = null): void; public function getMobilePhone(): ?PhoneNumber; diff --git a/src/Application/Contracts/ContactPersons/Entity/FullName.php b/src/Application/Contracts/ContactPersons/Entity/FullName.php index 8dfc1de5..18892be2 100644 --- a/src/Application/Contracts/ContactPersons/Entity/FullName.php +++ b/src/Application/Contracts/ContactPersons/Entity/FullName.php @@ -4,7 +4,9 @@ namespace Bitrix24\SDK\Application\Contracts\ContactPersons\Entity; -class FullName +use Stringable; + +class FullName implements Stringable { public function __construct( public string $name, @@ -15,8 +17,9 @@ public function __construct( if ($surname !== null) { $this->surname = trim($surname); } + if ($this->patronymic !== null) { - $this->patronymic = trim($patronymic); + $this->patronymic = trim((string) $patronymic); } } diff --git a/src/Application/Contracts/ContactPersons/Repository/ContactPersonRepositoryInterface.php b/src/Application/Contracts/ContactPersons/Repository/ContactPersonRepositoryInterface.php index 5b67f494..0a38fd97 100644 --- a/src/Application/Contracts/ContactPersons/Repository/ContactPersonRepositoryInterface.php +++ b/src/Application/Contracts/ContactPersons/Repository/ContactPersonRepositoryInterface.php @@ -35,26 +35,20 @@ public function getById(Uuid $uuid): ContactPersonInterface; /** * Find contact persons with email and filter by status and isEmailVerified flag * @param non-empty-string $email - * @param ContactPersonStatus|null $status - * @param bool|null $isEmailVerified * @return ContactPersonInterface[] */ - public function findByEmail(string $email, ?ContactPersonStatus $status = null, ?bool $isEmailVerified = null): array; + public function findByEmail(string $email, ?ContactPersonStatus $contactPersonStatus = null, ?bool $isEmailVerified = null): array; /** * Find contact persons with PhoneNumber and filter by status and isEmailVerified flag - * @param PhoneNumber $phoneNumber - * @param ContactPersonStatus|null $status - * @param bool|null $isPhoneVerified * @return ContactPersonInterface[] */ - public function findByPhone(PhoneNumber $phoneNumber, ?ContactPersonStatus $status = null, ?bool $isPhoneVerified = null): array; + public function findByPhone(PhoneNumber $phoneNumber, ?ContactPersonStatus $contactPersonStatus = null, ?bool $isPhoneVerified = null): array; /** * Find contact person by external id * * @param non-empty-string $externalId - * @return ContactPersonInterface|null */ public function findByExternalId(string $externalId): ?ContactPersonInterface; } \ No newline at end of file diff --git a/src/Core/Batch.php b/src/Core/Batch.php index 38d1f540..04314109 100644 --- a/src/Core/Batch.php +++ b/src/Core/Batch.php @@ -390,15 +390,15 @@ public function getTraversableList( $keyId = $isCrmItemsInBatch ? 'id' : 'ID'; - $firstResultPage = $this->core->call($apiMethod, $params); - $totalElementsCount = $firstResultPage->getResponseData()->getPagination()->getTotal(); + $response = $this->core->call($apiMethod, $params); + $totalElementsCount = $response->getResponseData()->getPagination()->getTotal(); $this->logger->debug('getTraversableList.totalElementsCount', [ 'totalElementsCount' => $totalElementsCount, ]); // filtered elements count less than or equal one result page(50 elements) $elementsCounter = 0; if ($totalElementsCount <= self::MAX_ELEMENTS_IN_PAGE) { - foreach ($firstResultPage->getResponseData()->getResult() as $listElement) { + foreach ($response->getResponseData()->getResult() as $listElement) { ++$elementsCounter; if ($limit !== null && $elementsCounter > $limit) { return; @@ -416,7 +416,7 @@ public function getTraversableList( // return first page $lastElementIdInFirstPage = null; if ($isCrmItemsInBatch) { - foreach ($firstResultPage->getResponseData()->getResult()['items'] as $listElement) { + foreach ($response->getResponseData()->getResult()['items'] as $listElement) { ++$elementsCounter; $lastElementIdInFirstPage = (int)$listElement[$keyId]; if ($limit !== null && $elementsCounter > $limit) { @@ -426,7 +426,7 @@ public function getTraversableList( yield $listElement; } } else { - foreach ($firstResultPage->getResponseData()->getResult() as $listElement) { + foreach ($response->getResponseData()->getResult() as $listElement) { ++$elementsCounter; $lastElementIdInFirstPage = (int)$listElement[$keyId]; if ($limit !== null && $elementsCounter > $limit) { diff --git a/src/Core/Credentials/Scope.php b/src/Core/Credentials/Scope.php index b280269a..ca7671e0 100644 --- a/src/Core/Credentials/Scope.php +++ b/src/Core/Credentials/Scope.php @@ -83,7 +83,7 @@ class Scope */ public function __construct(array $scope = []) { - $scope = array_unique(array_map('strtolower', $scope)); + $scope = array_unique(array_map(strtolower(...), $scope)); sort($scope); if (count($scope) === 1 && $scope[0] === '') { $scope = [];