Skip to content

Commit 7d64002

Browse files
author
hywax
committed
docs: client methods phpdoc
1 parent 777289f commit 7d64002

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/Client.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@ class Client
1515
{
1616
public const API_BASE_PATH = 'https://api-metrika.yandex.ru';
1717

18+
/**
19+
* @var array<string, mixed>
20+
*/
1821
private array $config;
1922

2023
private ClientInterface $httpClient;
2124

2225
private LoggerInterface $logger;
2326

27+
/**
28+
* @param array<string, mixed> $config
29+
* @throws ClientException
30+
*/
2431
public function __construct(array $config = [])
2532
{
2633
$this->config = array_merge([
@@ -35,36 +42,71 @@ public function __construct(array $config = [])
3542
$this->httpClient = $this->createDefaultHttpClient();
3643
}
3744

45+
/**
46+
* Set AUTH token
47+
*
48+
* @param string $token
49+
* @return void
50+
*/
3851
public function setToken(string $token): void
3952
{
4053
$this->config['token'] = $token;
4154
}
4255

56+
/**
57+
* Set logger
58+
*
59+
* @param LoggerInterface $logger
60+
* @return void
61+
*/
4362
public function setLogger(LoggerInterface $logger): void
4463
{
4564
$this->logger = $logger;
4665
}
4766

67+
/**
68+
* Get logger
69+
*
70+
* @return LoggerInterface
71+
*/
4872
public function getLogger(): LoggerInterface
4973
{
5074
return $this->logger;
5175
}
5276

77+
/**
78+
* Set HTTP client
79+
*
80+
* @param ClientInterface $httpClient
81+
* @return void
82+
*/
5383
public function setHttpClient(ClientInterface $httpClient): void
5484
{
5585
$this->httpClient = $httpClient;
5686
}
5787

88+
/**
89+
* Get HTTP client
90+
*
91+
* @return ClientInterface
92+
*/
5893
public function getHttpClient(): ClientInterface
5994
{
6095
return $this->httpClient;
6196
}
6297

98+
/**
99+
* Execute HTTP request
100+
*
101+
* @param RequestInterface $request
102+
* @return array<mixed>
103+
* @throws ClientException
104+
*/
63105
public function execute(RequestInterface $request): array
64106
{
65107
try {
66108
$request = $request->withHeader('Authorization', sprintf('OAuth %s', $this->config['token']));
67-
$response = $this->httpClient->sendRequest($request);
109+
$response = $this->httpClient->send($request);
68110
} catch (ClientExceptionInterface $e) {
69111
$this->getLogger()->error($e->getMessage());
70112

@@ -74,6 +116,11 @@ public function execute(RequestInterface $request): array
74116
return json_decode($response->getBody(), true);
75117
}
76118

119+
/**
120+
* Create default logger
121+
*
122+
* @return LoggerInterface
123+
*/
77124
protected function createDefaultLogger(): LoggerInterface
78125
{
79126
$logger = new Logger('ya-metrika-php-client');
@@ -83,6 +130,11 @@ protected function createDefaultLogger(): LoggerInterface
83130
return $logger;
84131
}
85132

133+
/**
134+
* Create default HTTP client
135+
*
136+
* @return ClientInterface
137+
*/
86138
protected function createDefaultHttpClient(): ClientInterface
87139
{
88140
return new GuzzleClient([

0 commit comments

Comments
 (0)