Skip to content

Commit 8bd3a27

Browse files
authored
Merge pull request #10 from polidog/feat/php8-syntax
細かいSyntaxの修正
2 parents 8a5304c + 3f68931 commit 8bd3a27

4 files changed

Lines changed: 21 additions & 36 deletions

File tree

src/Api.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,10 @@
1010
/**
1111
* Class ApiMethods.
1212
*/
13-
class Api
13+
final class Api
1414
{
15-
/**
16-
* @var ClientInterface
17-
*/
18-
private $client;
19-
20-
/**
21-
* @var string
22-
*/
23-
private $currentTeam;
24-
25-
public function __construct(ClientInterface $client, string $currentTeam)
15+
public function __construct(private ClientInterface $client, private string $currentTeam)
2616
{
27-
$this->client = $client;
28-
$this->currentTeam = $currentTeam;
2917
}
3018

3119
public function user(array $params = []): array

src/Client/Authorization.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@
99
use Psr\Http\Message\MessageInterface;
1010
use Psr\Http\Message\RequestInterface;
1111

12-
class Authorization
12+
final class Authorization
1313
{
14-
/**
15-
* @var string
16-
*/
17-
private $accessToken;
18-
19-
public function __construct(string $accessToken)
14+
public function __construct(private string $accessToken)
2015
{
21-
$this->accessToken = $accessToken;
2216
}
2317

2418
public function push(HandlerStack $stack): void

src/Client/Client.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@
1111

1212
final class Client implements ClientInterface
1313
{
14-
/**
15-
* @var string
16-
*/
17-
private $accessToken;
18-
19-
/**
20-
* @var HttpClientInterface
21-
*/
22-
private $httpClient;
23-
2414
/**
2515
* @var array
2616
*/
@@ -34,29 +24,29 @@ final class Client implements ClientInterface
3424
],
3525
];
3626

37-
public function __construct(HttpClientInterface $httpClient)
27+
public function __construct(private HttpClientInterface $httpClient)
3828
{
39-
$this->httpClient = $httpClient;
4029
}
4130

4231
/**
4332
* @throws ClientException
4433
* @throws \RuntimeException
34+
* @throws \JsonException
4535
*/
4636
public function request(string $method, string $path, array $data = []): array
4737
{
4838
try {
4939
$response = $this->httpClient->request($method, $path, $data);
5040

51-
return json_decode($response->getBody()->getContents(), true);
41+
return json_decode($response->getBody()->getContents(), true, 512, JSON_THROW_ON_ERROR);
5242
} catch (GuzzleException $e) {
5343
throw ClientException::newException($e, $method, $path, $data);
5444
}
5545
}
5646

5747
public static function factory(string $accessToken, array $httpOptions = []): self
5848
{
59-
$httpOptions = array_merge(static::$httpOptions, $httpOptions);
49+
$httpOptions = array_merge(self::$httpOptions, $httpOptions);
6050
$authorization = new Authorization($accessToken);
6151

6252
$httpOptions['handler'] = HandlerStack::create();

tests/Client/ClientTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ public function testRequest(): void
4242
$client = new Client($httpClient->reveal());
4343
$client->request('GET', '/test', ['query' => ['a' => 'b']]);
4444
$httpClient->request('GET', '/test', ['query' => ['a' => 'b']]);
45+
46+
47+
$stream->getContents()
48+
->willReturn(json_encode(['a' => 'b']))
49+
->shouldHaveBeenCalledOnce();
50+
51+
$response->getBody()
52+
->willReturn($stream->reveal())
53+
->shouldHaveBeenCalledOnce();
54+
55+
$httpClient->request(Argument::any(), Argument::any(), Argument::any())
56+
->willReturn($response->reveal())
57+
->shouldHaveBeenCalledOnce();
4558
}
4659

4760
public function testRequestException(): void

0 commit comments

Comments
 (0)