Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@
xmlns:xs="https://www.w3.org/2001/XMLSchema"
xmlns:orm="https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Bitrix24\Lib\Bitrix24Accounts\Entity\Bitrix24Account" table="bitrix24account">
<id name="uuid" type="uuid" column="uuid">
<generator strategy="CUSTOM"/>
<custom-id-generator class="Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator"/>
<id name="id" type="uuid" column="id">

</id>

<field name="bitrix24UserId" type="integer" column="b24_user_id" nullable="false"/>

<field name="isBitrix24UserAdmin" type="boolean" column="is_b24_user_admin" nullable="false"/>

<field name="memberId" type="string" column="member_id" nullable="false"/>

<field name="domainUrl" type="string" column="domain_url" nullable="false"/>

<field name="accountStatus" enum-type="string" column="account_status" nullable="false"/>
<field name="status" enum-type="string" column="status" nullable="false"/>

<embedded name="authToken" class="Bitrix24\SDK\Core\Credentials\AuthToken"/>
<field name="applicationToken" type="string" column="application_token" nullable="true"/>

<field name="createdAt" type="datetime_immutable" column="created_at_utc" precision="3" nullable="false"/>
<field name="createdAt" type="carbon_immutable" column="created_at_utc" precision="3" nullable="false"/>

<field name="updatedAt" type="datetime_immutable" column="update_at_utc" precision="3" nullable="false"/>
<field name="updatedAt" type="carbon_immutable" column="update_at_utc" precision="3" nullable="false"/>

<field name="applicationVersion" type="integer" column="application_version" nullable="false"/>

<embedded name="authToken" class="Bitrix24\SDK\Core\Credentials\AuthToken"/>

<embedded name="applicationScope" class="Bitrix24\SDK\Core\Credentials\Scope"/>
</entity>
</doctrine-mapping>
60 changes: 30 additions & 30 deletions src/Bitrix24Accounts/Entity/Bitrix24Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

private ?string $comment = null;

private AuthToken $authToken;

Check failure on line 54 in src/Bitrix24Accounts/Entity/Bitrix24Account.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, highest, ubuntu-latest)

Property Bitrix24\Lib\Bitrix24Accounts\Entity\Bitrix24Account::$authToken is never read, only written.

/**
* @var Event[]
Expand All @@ -62,23 +62,23 @@
public function __construct(
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
private Uuid $uuid,
private Uuid $id,
#[ORM\Column(name: 'b24_user_id', type: 'integer', nullable: false)]
#[SerializedName('b24_user_id')]
private readonly int $bitrix24UserId,
#[ORM\Column(name: 'is_b24_user_admin', type: 'boolean', nullable: false)]
#[SerializedName('is_b24_user_admin')]
private readonly bool $isBitrix24UserAdmin,
private readonly bool $isBitrix24UserAdmin,
/** bitrix24 portal unique id */
#[ORM\Column(name: 'member_id', type: 'string', nullable: false)]
#[SerializedName('member_id')]
private readonly string $memberId,
private readonly string $memberId,
#[ORM\Column(name: 'domain_url', type: 'string', nullable: false)]
#[SerializedName('domain_url')]
private string $domainUrl,
#[ORM\Column(name: 'account_status', type: 'string', nullable: false, enumType: Bitrix24AccountStatus::class)]
private Bitrix24AccountStatus $accountStatus,
AuthToken $authToken,
private Bitrix24AccountStatus $status,
AuthToken $authToken,
#[ORM\Column(name: 'created_at_utc', type: 'carbon_immutable', precision: 3, nullable: false)]
#[Ignore]
private readonly CarbonImmutable $createdAt,
Expand All @@ -101,7 +101,7 @@
#[Override]
public function getId(): Uuid
{
return $this->uuid;
return $this->id;
}

#[Override]
Expand Down Expand Up @@ -131,7 +131,7 @@
#[Override]
public function getStatus(): Bitrix24AccountStatus
{
return $this->accountStatus;
return $this->status;
}

#[Override]
Expand All @@ -151,7 +151,7 @@
sprintf(
'member id %s for bitrix24 account %s for domain %s mismatch with member id %s for renewed access token',
$this->memberId,
$this->uuid->toRfc4122(),
$this->id->toRfc4122(),
$this->domainUrl,
$renewedAuthToken->memberId,
)
Expand Down Expand Up @@ -189,21 +189,21 @@
throw new InvalidArgumentException('new domain url cannot be empty');
}

if (Bitrix24AccountStatus::blocked === $this->accountStatus || Bitrix24AccountStatus::deleted === $this->accountStatus) {
if (Bitrix24AccountStatus::blocked === $this->status || Bitrix24AccountStatus::deleted === $this->status) {
throw new InvalidArgumentException(
sprintf(
'bitrix24 account %s for domain %s must be in active or new state, now account in %s state. domain url cannot be changed',
$this->uuid->toRfc4122(),
$this->id->toRfc4122(),
$this->domainUrl,
$this->accountStatus->name
$this->status->name
)
);
}

$this->domainUrl = $newDomainUrl;
$this->updatedAt = new CarbonImmutable();
$this->events[] = new Bitrix24AccountDomainUrlChangedEvent(
$this->uuid,
$this->id,
new CarbonImmutable()
);
}
Expand All @@ -214,21 +214,21 @@
#[Override]
public function applicationInstalled(string $applicationToken): void
{
if (Bitrix24AccountStatus::new !== $this->accountStatus) {
if (Bitrix24AccountStatus::new !== $this->status) {
throw new InvalidArgumentException(sprintf(
'for finish installation bitrix24 account must be in status «new», current status - «%s»',
$this->accountStatus->name));
$this->status->name));
}

if ($applicationToken === '') {
throw new InvalidArgumentException('application token cannot be empty');
}

$this->accountStatus = Bitrix24AccountStatus::active;
$this->status = Bitrix24AccountStatus::active;
$this->applicationToken = $applicationToken;
$this->updatedAt = new CarbonImmutable();
$this->events[] = new Bitrix24AccountApplicationInstalledEvent(
$this->uuid,
$this->id,
new CarbonImmutable()
);
}
Expand All @@ -243,10 +243,10 @@
throw new InvalidArgumentException('application token cannot be empty');
}

if (Bitrix24AccountStatus::active !== $this->accountStatus) {
if (Bitrix24AccountStatus::active !== $this->status) {
throw new InvalidArgumentException(sprintf(
'for uninstall account must be in status «active», current status - «%s»',
$this->accountStatus->name));
$this->status->name));
}

if ($this->applicationToken !== $applicationToken) {
Expand All @@ -255,16 +255,16 @@
'application token «%s» mismatch with application token «%s» for bitrix24 account %s for domain %s',
$applicationToken,
$this->applicationToken,
$this->uuid->toRfc4122(),
$this->id->toRfc4122(),
$this->domainUrl
)
);
}

$this->accountStatus = Bitrix24AccountStatus::deleted;
$this->status = Bitrix24AccountStatus::deleted;
$this->updatedAt = new CarbonImmutable();
$this->events[] = new Bitrix24AccountApplicationUninstalledEvent(
$this->uuid,
$this->id,
new CarbonImmutable()
);
}
Expand Down Expand Up @@ -293,8 +293,8 @@
#[Override]
public function updateApplicationVersion(int $version, ?Scope $newScope): void
{
if (Bitrix24AccountStatus::active !== $this->accountStatus) {
throw new InvalidArgumentException(sprintf('account must be in status «active», but now account in status «%s»', $this->accountStatus->name));
if (Bitrix24AccountStatus::active !== $this->status) {
throw new InvalidArgumentException(sprintf('account must be in status «active», but now account in status «%s»', $this->status->name));
}

if ($this->applicationVersion >= $version) {
Expand All @@ -311,7 +311,7 @@

$this->updatedAt = new CarbonImmutable();
$this->events[] = new Bitrix24AccountApplicationVersionUpdatedEvent(
$this->uuid,
$this->id,
new CarbonImmutable()
);
}
Expand All @@ -322,13 +322,13 @@
#[Override]
public function markAsActive(?string $comment): void
{
if (Bitrix24AccountStatus::blocked !== $this->accountStatus) {
if (Bitrix24AccountStatus::blocked !== $this->status) {
throw new InvalidArgumentException(
sprintf('you can activate account only in status blocked, now account in status %s',
$this->accountStatus->name));
$this->status->name));
}

$this->accountStatus = Bitrix24AccountStatus::active;
$this->status = Bitrix24AccountStatus::active;
$this->comment = $comment;
$this->updatedAt = new CarbonImmutable();
}
Expand All @@ -339,15 +339,15 @@
#[Override]
public function markAsBlocked(?string $comment): void
{
if (Bitrix24AccountStatus::deleted === $this->accountStatus) {
if (Bitrix24AccountStatus::deleted === $this->status) {
throw new InvalidArgumentException('you cannot block account in status «deleted»');
}

$this->accountStatus = Bitrix24AccountStatus::blocked;
$this->status = Bitrix24AccountStatus::blocked;
$this->comment = $comment;
$this->updatedAt = new CarbonImmutable();
$this->events[] = new Bitrix24AccountBlockedEvent(
$this->uuid,
$this->id,
new CarbonImmutable()
);
}
Expand Down
Loading