Skip to content

Commit

Permalink
Refactor code for improved readability and consistency
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mesilov committed Jul 21, 2024
1 parent 9985327 commit 0e9e091
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;

/**
Expand All @@ -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;

Expand Down
7 changes: 5 additions & 2 deletions src/Application/Contracts/ContactPersons/Entity/FullName.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 5 additions & 5 deletions src/Core/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Credentials/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down

0 comments on commit 0e9e091

Please sign in to comment.