Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 2afc7d6

Browse files
committed
Refactor tests and classes to use PHP attributes
This commit updates all test cases to use native PHP8 attribute syntax instead of comments for PHPUnit annotations. The method visibility has also been adjusted to be compliant with the PHPUnit v9. Additionally, multiple unnecessary comment blocks have been removed from the source codes for better readability. All changes have been made across various classes and test cases. Signed-off-by: mesilov <[email protected]>
1 parent d04c08a commit 2afc7d6

27 files changed

+199
-296
lines changed

phpstan.neon.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ parameters:
44
- src/
55
- tests/Integration/Services/Telephony
66
- tests/Integration/Services/User
7+
- tests/Unit/
78
bootstrapFiles:
89
- tests/bootstrap.php
910
parallel:
1011
jobSize: 20
1112
maximumNumberOfProcesses: 8
1213
minimumNumberOfJobsPerProcess: 2
1314
editorUrlTitle: '%%relFile%%:%%line%%'
14-
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
15+
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
16+
treatPhpDocTypesAsCertain: false

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
return RectorConfig::configure()
1111
->withPaths([
1212
__DIR__ . '/src/Core/',
13+
__DIR__ . '/src/Application/',
1314
__DIR__ . '/src/Services/Telephony',
1415
__DIR__ . '/tests/Integration/Services/Telephony',
1516
__DIR__ . '/src/Services/User',
1617
__DIR__ . '/tests/Integration/Services/User',
18+
__DIR__ . '/tests/Unit/',
1719
])
1820
->withCache(cacheDirectory: __DIR__ . '.cache/rector')
1921
->withSets(

src/Application/ApplicationStatus.php

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
class ApplicationStatus
1111
{
1212
private const STATUS_SHORT_FREE = 'F';
13+
1314
private const STATUS_SHORT_DEMO = 'D';
15+
1416
private const STATUS_SHORT_TRIAL = 'T';
17+
1518
private const STATUS_SHORT_PAID = 'P';
19+
1620
private const STATUS_SHORT_LOCAL = 'L';
21+
1722
private const STATUS_SHORT_SUBSCRIPTION = 'S';
18-
private string $statusCode;
23+
24+
private readonly string $statusCode;
1925

2026
/**
21-
* @param string $statusShortCode
22-
*
2327
* @throws InvalidArgumentException
2428
*/
2529
public function __construct(string $statusShortCode)
@@ -42,17 +46,11 @@ public static function free(): self
4246
return new self(self::STATUS_SHORT_FREE);
4347
}
4448

45-
/**
46-
* @return bool
47-
*/
4849
public function isFree(): bool
4950
{
5051
return 'free' === $this->statusCode;
5152
}
5253

53-
/**
54-
* @return bool
55-
*/
5654
public function isDemo(): bool
5755
{
5856
return 'demo' === $this->statusCode;
@@ -63,9 +61,6 @@ public static function demo(): self
6361
return new self(self::STATUS_SHORT_DEMO);
6462
}
6563

66-
/**
67-
* @return bool
68-
*/
6964
public function isTrial(): bool
7065
{
7166
return 'trial' === $this->statusCode;
@@ -76,9 +71,6 @@ public static function trial(): self
7671
return new self(self::STATUS_SHORT_TRIAL);
7772
}
7873

79-
/**
80-
* @return bool
81-
*/
8274
public function isPaid(): bool
8375
{
8476
return 'paid' === $this->statusCode;
@@ -89,9 +81,6 @@ public static function paid(): self
8981
return new self(self::STATUS_SHORT_PAID);
9082
}
9183

92-
/**
93-
* @return bool
94-
*/
9584
public function isLocal(): bool
9685
{
9786
return 'local' === $this->statusCode;
@@ -102,9 +91,6 @@ public static function local(): self
10291
return new self(self::STATUS_SHORT_LOCAL);
10392
}
10493

105-
/**
106-
* @return bool
107-
*/
10894
public function isSubscription(): bool
10995
{
11096
return 'subscription' === $this->statusCode;
@@ -115,18 +101,12 @@ public static function subscription(): self
115101
return new self(self::STATUS_SHORT_SUBSCRIPTION);
116102
}
117103

118-
/**
119-
* @return string
120-
*/
121104
public function getStatusCode(): string
122105
{
123106
return $this->statusCode;
124107
}
125108

126109
/**
127-
* @param Request $request
128-
*
129-
* @return self
130110
* @throws InvalidArgumentException
131111
*/
132112
public static function initFromRequest(Request $request): self
@@ -135,9 +115,6 @@ public static function initFromRequest(Request $request): self
135115
}
136116

137117
/**
138-
* @param string $shortStatusCode
139-
*
140-
* @return self
141118
* @throws InvalidArgumentException
142119
*/
143120
public static function initFromString(string $shortStatusCode): self

src/Application/Contracts/Bitrix24Accounts/Entity/Bitrix24AccountInterface.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,7 @@ public function getStatus(): Bitrix24AccountStatus;
4848
*/
4949
public function getAuthToken(): AuthToken;
5050

51-
/**
52-
* @param RenewedAuthToken $renewedAuthToken
53-
*
54-
* @return void
55-
*/
51+
5652
public function renewAuthToken(RenewedAuthToken $renewedAuthToken): void;
5753

5854
/**

src/Application/Contracts/Bitrix24Accounts/Repository/Bitrix24AccountRepositoryInterface.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ interface Bitrix24AccountRepositoryInterface
1212
/**
1313
* Get Bitrix24 account by id
1414
*/
15-
public function getById(Uuid $id): Bitrix24Accounts\Entity\Bitrix24AccountInterface;
15+
public function getById(Uuid $uuid): Bitrix24Accounts\Entity\Bitrix24AccountInterface;
1616

1717
/**
18-
* @param Bitrix24Accounts\Entity\Bitrix24AccountInterface $entity
1918
* @param bool $isFlush save entity to storage, commit transaction in oltp database
2019
*/
21-
public function save(Bitrix24Accounts\Entity\Bitrix24AccountInterface $entity, bool $isFlush = false): void;
20+
public function save(Bitrix24Accounts\Entity\Bitrix24AccountInterface $bitrix24Account, bool $isFlush = false): void;
2221
}

src/Application/Requests/AbstractRequest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@
88

99
abstract class AbstractRequest
1010
{
11-
protected Request $request;
12-
13-
/**
14-
* @param \Symfony\Component\HttpFoundation\Request $request
15-
*/
16-
public function __construct(Request $request)
11+
public function __construct(protected Request $request)
1712
{
18-
$this->request = $request;
1913
}
2014

21-
/**
22-
* @return \Symfony\Component\HttpFoundation\Request
23-
*/
2415
public function getRequest(): Request
2516
{
2617
return $this->request;

src/Application/Requests/Events/AbstractEventRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
abstract class AbstractEventRequest extends AbstractRequest implements EventInterface
1111
{
1212
protected string $eventCode;
13+
1314
protected int $timestamp;
15+
1416
protected array $eventPayload;
17+
1518
protected int $eventId;
1619

17-
/**
18-
* @param Request $request
19-
*/
2020
public function __construct(Request $request)
2121
{
2222
parent::__construct($request);

src/Application/Requests/Placement/PlacementRequest.php

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@
1212

1313
class PlacementRequest extends AbstractRequest
1414
{
15-
private AuthToken $accessToken;
16-
private string $memberId;
17-
private ApplicationStatus $applicationStatus;
18-
private string $code;
15+
private readonly AuthToken $accessToken;
16+
17+
private readonly string $memberId;
18+
19+
private readonly ApplicationStatus $applicationStatus;
20+
21+
private readonly string $code;
22+
1923
/**
2024
* @var array<string, mixed>
2125
*/
22-
private array $placementOptions;
23-
private string $domainUrl;
24-
private string $languageCode;
26+
private readonly array $placementOptions;
27+
28+
private readonly string $domainUrl;
29+
30+
private readonly string $languageCode;
2531

2632
/**
27-
* @param \Symfony\Component\HttpFoundation\Request $request
2833
*
2934
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
3035
* @throws \JsonException
@@ -47,10 +52,12 @@ public function __construct(Request $request)
4752
if ($options === null) {
4853
throw new InvalidArgumentException('invalid data in PLACEMENT_OPTIONS json payload');
4954
}
55+
5056
// fix "undefined" string in options when placement loaded in telephony settings
5157
if (!is_array($options)) {
5258
$options = [];
5359
}
60+
5461
$this->placementOptions = $options;
5562
}
5663

@@ -59,50 +66,35 @@ public function getApplicationStatus(): ApplicationStatus
5966
return $this->applicationStatus;
6067
}
6168

62-
/**
63-
* @return string
64-
*/
6569
public function getMemberId(): string
6670
{
6771
return $this->memberId;
6872
}
6973

70-
/**
71-
* @return \Bitrix24\SDK\Core\Credentials\AuthToken
72-
*/
7374
public function getAccessToken(): AuthToken
7475
{
7576
return $this->accessToken;
7677
}
7778

78-
/**
79-
* @return string
80-
*/
8179
public function getCode(): string
8280
{
8381
return $this->code;
8482
}
8583

86-
/**
87-
* @return array|mixed
88-
*/
89-
public function getPlacementOptions()
84+
85+
public function getPlacementOptions(): array
9086
{
9187
return $this->placementOptions;
9288
}
9389

94-
/**
95-
* @return mixed|string
96-
*/
97-
public function getDomainUrl()
90+
91+
public function getDomainUrl(): string
9892
{
9993
return $this->domainUrl;
10094
}
10195

102-
/**
103-
* @return mixed|string
104-
*/
105-
public function getLanguageCode()
96+
97+
public function getLanguageCode(): string
10698
{
10799
return $this->languageCode;
108100
}

tests/Unit/Application/ApplicationStatusTest.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
use Generator;
1010
use PHPUnit\Framework\TestCase;
1111

12+
#[\PHPUnit\Framework\Attributes\CoversClass(\Bitrix24\SDK\Application\ApplicationStatus::class)]
1213
class ApplicationStatusTest extends TestCase
1314
{
1415
/**
15-
* @param string $shortCode
16-
* @param string $longCode
1716
*
18-
* @return void
19-
* @dataProvider statusDataProvider
2017
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
2118
*/
19+
#[\PHPUnit\Framework\Attributes\DataProvider('statusDataProvider')]
2220
public function testGetStatusCode(string $shortCode, string $longCode): void
2321
{
2422
$this->assertEquals(
@@ -27,19 +25,14 @@ public function testGetStatusCode(string $shortCode, string $longCode): void
2725
);
2826
}
2927

30-
/**
31-
* @return void
32-
*/
3328
public function testInvalidStatusCode(): void
3429
{
3530
$this->expectException(InvalidArgumentException::class);
3631
new ApplicationStatus('foo');
3732
}
3833

3934
/**
40-
* @return void
4135
* @throws \Bitrix24\SDK\Core\Exceptions\InvalidArgumentException
42-
* @covers \Bitrix24\SDK\Application\ApplicationStatus::initFromString
4336
*/
4437
public function testInitFromString(): void
4538
{
@@ -76,9 +69,6 @@ public function testSubscription(): void
7669
$this->assertTrue(ApplicationStatus::subscription()->isSubscription());
7770
}
7871

79-
/**
80-
* @return \Generator
81-
*/
8272
public static function statusDataProvider(): Generator
8373
{
8474
yield 'free' => [

tests/Unit/Application/Contracts/Bitrix24Accounts/Entity/Bitrix24AccountInterfaceReferenceImplementationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
class Bitrix24AccountInterfaceReferenceImplementationTest extends Bitrix24AccountInterfaceTest
2020
{
2121
protected function createBitrix24AccountImplementation(
22-
Uuid $id,
22+
Uuid $uuid,
2323
int $bitrix24UserId,
2424
bool $isBitrix24UserAdmin,
2525
string $memberId,
2626
string $domainUrl,
27-
Bitrix24AccountStatus $accountStatus,
27+
Bitrix24AccountStatus $bitrix24AccountStatus,
2828
AuthToken $authToken,
2929
CarbonImmutable $createdAt,
3030
CarbonImmutable $updatedAt,
@@ -33,12 +33,12 @@ protected function createBitrix24AccountImplementation(
3333
): Bitrix24AccountInterface
3434
{
3535
return new Bitrix24AccountReferenceEntityImplementation(
36-
$id,
36+
$uuid,
3737
$bitrix24UserId,
3838
$isBitrix24UserAdmin,
3939
$memberId,
4040
$domainUrl,
41-
$accountStatus,
41+
$bitrix24AccountStatus,
4242
$authToken,
4343
$createdAt,
4444
$updatedAt,

0 commit comments

Comments
 (0)