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

Commit 5a268d7

Browse files
committed
fix method name in ContactsResult
1 parent 1ea1d7f commit 5a268d7

File tree

10 files changed

+94
-98
lines changed

10 files changed

+94
-98
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
* change in scope «CRM» Product service and integration tests
77
* add `AddedItemIdResultInterface` for batch-queries result
88
* fix method name in `ContactsResult`
9+
* add interface `ApiClientInterface`
10+
* bump phpunit version
11+
* bump phpstan version
912

1013
## 2.0-alpha.2 (31.01.2021)
1114

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"symfony/console": "5.2.*",
3333
"symfony/dotenv": "5.2.*",
3434
"symfony/debug-bundle": "5.2.*",
35-
"phpstan/phpstan": "0.12.59",
36-
"phpunit/phpunit": "9.3.*",
35+
"phpstan/phpstan": "1.1.*",
36+
"phpunit/phpunit": "9.5.*",
3737
"roave/security-advisories": "dev-master"
3838
},
3939
"autoload": {

src/Core/ApiClient.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,19 @@
44

55
namespace Bitrix24\SDK\Core;
66

7+
use Bitrix24\SDK\Core\Contracts\ApiClientInterface;
78
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
89
use Bitrix24\SDK\Core\Response\DTO\RenewedAccessToken;
910
use Psr\Log\LoggerInterface;
1011
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
1112
use Symfony\Contracts\HttpClient\HttpClientInterface;
1213
use Symfony\Contracts\HttpClient\ResponseInterface;
1314

14-
/**
15-
* Class ApiClient
16-
*
17-
* @package Bitrix24\SDK\Core
18-
*/
19-
class ApiClient
15+
class ApiClient implements ApiClientInterface
2016
{
21-
/**
22-
* @var HttpClientInterface
23-
*/
24-
protected $client;
25-
/**
26-
* @var LoggerInterface
27-
*/
28-
protected $logger;
29-
/**
30-
* @var Credentials\Credentials
31-
*/
32-
protected $credentials;
17+
protected HttpClientInterface $client;
18+
protected LoggerInterface $logger;
19+
protected Credentials\Credentials $credentials;
3320
/**
3421
* @const string
3522
*/
@@ -90,12 +77,12 @@ public function getCredentials(): Credentials\Credentials
9077
*/
9178
public function getNewAccessToken(): RenewedAccessToken
9279
{
93-
$this->logger->debug(sprintf('getNewAccessToken.start'));
80+
$this->logger->debug('getNewAccessToken.start');
9481
if ($this->getCredentials()->getApplicationProfile() === null) {
95-
throw new InvalidArgumentException(sprintf('application profile not set'));
82+
throw new InvalidArgumentException('application profile not set');
9683
}
9784
if ($this->getCredentials()->getAccessToken() === null) {
98-
throw new InvalidArgumentException(sprintf('access token in credentials not set'));
85+
throw new InvalidArgumentException('access token in credentials not set');
9986
}
10087

10188
$method = 'GET';
@@ -119,7 +106,7 @@ public function getNewAccessToken(): RenewedAccessToken
119106
$result = $response->toArray(false);
120107
$newAccessToken = RenewedAccessToken::initFromArray($result);
121108

122-
$this->logger->debug(sprintf('getNewAccessToken.finish'));
109+
$this->logger->debug('getNewAccessToken.finish');
123110

124111
return $newAccessToken;
125112
}

src/Core/ApiLevelErrorHandler.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
*/
1919
class ApiLevelErrorHandler
2020
{
21-
/**
22-
* @var LoggerInterface
23-
*/
24-
protected $logger;
21+
protected LoggerInterface $logger;
2522
protected const ERROR_KEY = 'error';
2623
protected const ERROR_DESCRIPTION_KEY = 'error_description';
2724

@@ -58,9 +55,9 @@ public function handle(array $responseBody): void
5855
);
5956
switch ($errorCode) {
6057
case 'query_limit_exceeded':
61-
throw new QueryLimitExceededException(sprintf('query limit exceeded - too many requests'));
58+
throw new QueryLimitExceededException('query limit exceeded - too many requests');
6259
case 'error_method_not_found':
63-
throw new MethodNotFoundException(sprintf('api method not found'));
60+
throw new MethodNotFoundException('api method not found');
6461
default:
6562
throw new BaseException(sprintf('%s - %s', $errorCode, $errorDescription));
6663
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Core\Contracts;
6+
7+
use Bitrix24\SDK\Core\Credentials\Credentials;
8+
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
9+
use Bitrix24\SDK\Core\Response\DTO\RenewedAccessToken;
10+
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
11+
use Symfony\Contracts\HttpClient\ResponseInterface;
12+
13+
interface ApiClientInterface
14+
{
15+
/**
16+
* @param string $apiMethod
17+
* @param array $parameters
18+
*
19+
* @return ResponseInterface
20+
* @throws TransportExceptionInterface
21+
* @throws InvalidArgumentException
22+
*/
23+
public function getResponse(string $apiMethod, array $parameters = []): ResponseInterface;
24+
25+
/**
26+
* @return RenewedAccessToken
27+
* @throws InvalidArgumentException
28+
* @throws TransportExceptionInterface
29+
*/
30+
public function getNewAccessToken(): RenewedAccessToken;
31+
32+
/**
33+
* @return Credentials
34+
*/
35+
public function getCredentials(): Credentials;
36+
}

src/Core/Contracts/CoreInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ interface CoreInterface
2424
* @throws TransportException
2525
*/
2626
public function call(string $apiMethod, array $parameters = []): Response;
27+
28+
/**
29+
* @return \Bitrix24\SDK\Core\Contracts\ApiClientInterface
30+
*/
31+
public function getApiClient(): ApiClientInterface;
2732
}

src/Core/Core.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Bitrix24\SDK\Core;
66

77
use Bitrix24\SDK\Core\Commands\Command;
8+
use Bitrix24\SDK\Core\Contracts\ApiClientInterface;
89
use Bitrix24\SDK\Core\Contracts\CoreInterface;
910
use Bitrix24\SDK\Core\Exceptions\BaseException;
1011
use Bitrix24\SDK\Core\Exceptions\TransportException;
@@ -22,33 +23,21 @@
2223
*/
2324
class Core implements CoreInterface
2425
{
25-
/**
26-
* @var ApiClient
27-
*/
28-
protected ApiClient $apiClient;
29-
/**
30-
* @var LoggerInterface
31-
*/
26+
protected ApiClientInterface $apiClient;
3227
protected LoggerInterface $logger;
33-
/**
34-
* @var EventDispatcherInterface
35-
*/
3628
protected EventDispatcherInterface $eventDispatcher;
37-
/**
38-
* @var ApiLevelErrorHandler
39-
*/
4029
protected ApiLevelErrorHandler $apiLevelErrorHandler;
4130

4231
/**
4332
* Main constructor.
4433
*
45-
* @param ApiClient $apiClient
34+
* @param ApiClientInterface $apiClient
4635
* @param ApiLevelErrorHandler $apiLevelErrorHandler
4736
* @param EventDispatcherInterface $eventDispatcher
4837
* @param LoggerInterface $logger
4938
*/
5039
public function __construct(
51-
ApiClient $apiClient,
40+
ApiClientInterface $apiClient,
5241
ApiLevelErrorHandler $apiLevelErrorHandler,
5342
EventDispatcherInterface $eventDispatcher,
5443
LoggerInterface $logger
@@ -179,4 +168,12 @@ public function call(string $apiMethod, array $parameters = []): Response
179168

180169
return $response;
181170
}
171+
172+
/**
173+
* @return \Bitrix24\SDK\Core\Contracts\ApiClientInterface
174+
*/
175+
public function getApiClient(): ApiClientInterface
176+
{
177+
return $this->apiClient;
178+
}
182179
}

src/Core/CoreBuilder.php

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Bitrix24\SDK\Core;
66

7+
use Bitrix24\SDK\Core\Contracts\ApiClientInterface;
78
use Bitrix24\SDK\Core\Contracts\CoreInterface;
89
use Bitrix24\SDK\Core\Credentials\Credentials;
910
use Bitrix24\SDK\Core\Credentials\WebhookUrl;
@@ -22,34 +23,13 @@
2223
*/
2324
class CoreBuilder
2425
{
25-
/**
26-
* @var ApiClient|null
27-
*/
28-
protected $apiClient;
29-
/**
30-
* @var HttpClientInterface
31-
*/
32-
protected $httpClient;
33-
/**
34-
* @var EventDispatcherInterface
35-
*/
36-
protected $eventDispatcher;
37-
/**
38-
* @var LoggerInterface
39-
*/
40-
protected $logger;
41-
/**
42-
* @var WebhookUrl|null
43-
*/
44-
protected $webhookUrl;
45-
/**
46-
* @var Credentials|null
47-
*/
48-
protected $credentials;
49-
/**
50-
* @var ApiLevelErrorHandler
51-
*/
52-
protected $apiLevelErrorHandler;
26+
protected ?ApiClientInterface $apiClient;
27+
protected HttpClientInterface $httpClient;
28+
protected EventDispatcherInterface $eventDispatcher;
29+
protected LoggerInterface $logger;
30+
protected ?WebhookUrl $webhookUrl;
31+
protected ?Credentials $credentials;
32+
protected ApiLevelErrorHandler $apiLevelErrorHandler;
5333

5434
/**
5535
* CoreBuilder constructor.
@@ -83,11 +63,11 @@ public function withWebhookUrl(string $webhookUrl): self
8363
}
8464

8565
/**
86-
* @param ApiClient $apiClient
66+
* @param ApiClientInterface $apiClient
8767
*
8868
* @return $this
8969
*/
90-
public function withApiClient(ApiClient $apiClient): self
70+
public function withApiClient(ApiClientInterface $apiClient): self
9171
{
9272
$this->apiClient = $apiClient;
9373

@@ -127,7 +107,7 @@ public function build(): CoreInterface
127107
if ($this->webhookUrl !== null) {
128108
$this->credentials = Credentials::createForWebHook($this->webhookUrl);
129109
} elseif ($this->credentials === null) {
130-
throw new InvalidArgumentException(sprintf('you must set webhook url or oauth credentials'));
110+
throw new InvalidArgumentException('you must set webhook url or oauth credentials');
131111
}
132112

133113
if ($this->apiClient === null) {

src/Core/Credentials/Credentials.php

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,10 @@
1111
*/
1212
class Credentials
1313
{
14-
/**
15-
* @var WebhookUrl|null
16-
*/
17-
protected $webhookUrl;
18-
/**
19-
* @var AccessToken|null
20-
*/
21-
protected $accessToken;
22-
/**
23-
* @var ApplicationProfile|null
24-
*/
25-
protected $applicationProfile;
26-
27-
/**
28-
* @var string|null
29-
*/
30-
protected $domainUrl;
14+
protected ?WebhookUrl $webhookUrl;
15+
protected ?AccessToken $accessToken;
16+
protected ?ApplicationProfile $applicationProfile;
17+
protected ?string $domainUrl;
3118

3219
/**
3320
* Credentials constructor.
@@ -48,10 +35,10 @@ public function __construct(
4835
$this->applicationProfile = $applicationProfile;
4936
$this->domainUrl = $domainUrl;
5037
if ($this->accessToken === null && $this->webhookUrl === null) {
51-
throw new \LogicException(sprintf('you must set on of auth type: webhook or OAuth 2.0'));
38+
throw new \LogicException('you must set on of auth type: webhook or OAuth 2.0');
5239
}
5340
if ($this->accessToken !== null && $this->domainUrl === null) {
54-
throw new \LogicException(sprintf('for oauth type you must set domain url'));
41+
throw new \LogicException('for oauth type you must set domain url');
5542
}
5643
}
5744

@@ -77,7 +64,9 @@ public function getApplicationProfile(): ?ApplicationProfile
7764
public function getDomainUrl(): string
7865
{
7966
if ($this->getWebhookUrl() !== null) {
80-
$url = parse_url($this->getWebhookUrl()->getUrl())['host'];
67+
$arUrl = parse_url($this->getWebhookUrl()->getUrl());
68+
69+
$url = sprintf('%s://%s', $arUrl['scheme'], $arUrl['host']);
8170
} else {
8271
$url = $this->domainUrl;
8372
}

src/Services/AbstractService.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Bitrix24\SDK\Services;
66

7-
use Bitrix24\SDK\Core\Contracts\BatchInterface;
87
use Bitrix24\SDK\Core\Contracts\CoreInterface;
98
use Psr\Log\LoggerInterface;
109

@@ -15,7 +14,10 @@
1514
*/
1615
abstract class AbstractService
1716
{
18-
protected CoreInterface $core;
17+
/**
18+
* @property-read CoreInterface $core
19+
*/
20+
public CoreInterface $core;
1921
protected LoggerInterface $log;
2022

2123
/**

0 commit comments

Comments
 (0)