Skip to content

Commit 2a8aa70

Browse files
authored
Add property strict types (#60)
1 parent 231da6c commit 2a8aa70

File tree

11 files changed

+38
-196
lines changed

11 files changed

+38
-196
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"docs": "https://github.com/cybercog/youtrack-rest-php/wiki"
3737
},
3838
"require": {
39-
"php": "^8.0",
39+
"php": "^8.1",
4040
"ext-json": "*",
4141
"guzzlehttp/guzzle": "^7.8"
4242
},

contracts/Authenticator/Authenticator.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,12 @@ interface Authenticator
2020
/**
2121
* Authenticate API Client.
2222
*
23-
* @param \Cog\Contracts\YouTrack\Rest\Client\Client $client
24-
* @return void
25-
*
2623
* @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException
2724
*/
2825
public function authenticate(ClientInterface $client): void;
2926

3027
/**
3128
* Retrieve authentication token.
32-
*
33-
* @return string
3429
*/
3530
public function token(): string;
3631
}

contracts/Authorizer/Authorizer.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ interface Authorizer
1919
{
2020
/**
2121
* Append authorization headers to REST client.
22-
*
23-
* @param \Cog\Contracts\YouTrack\Rest\Client\Client $client
24-
* @return void
2522
*/
2623
public function appendHeadersTo(ClientInterface $client): void;
2724
}

contracts/Client/Client.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,6 @@ public function delete(string $uri, array $params = [], array $options = []): Re
9595

9696
/**
9797
* Write header value.
98-
*
99-
* @param string $key
100-
* @param string $value
101-
* @return void
10298
*/
10399
public function withHeader(string $key, string $value): void;
104100

contracts/Response/Response.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ interface Response
1919
{
2020
/**
2121
* Returns original HTTP client response.
22-
*
23-
* @return \Psr\Http\Message\ResponseInterface
2422
*/
2523
public function httpResponse(): PsrResponseInterface;
2624

@@ -29,37 +27,26 @@ public function httpResponse(): PsrResponseInterface;
2927
*
3028
* The status code is a 3-digit integer result code of the server's attempt
3129
* to understand and satisfy the request.
32-
*
33-
* @return int
3430
*/
3531
public function statusCode(): int;
3632

3733
/**
3834
* Retrieves a comma-separated string of the values for a single header.
39-
*
40-
* @param string $header
41-
* @return string
4235
*/
4336
public function header(string $header): string;
4437

4538
/**
4639
* Transform response cookie headers to string.
47-
*
48-
* @return string
4940
*/
5041
public function cookie(): string;
5142

5243
/**
5344
* Returns response location header.
54-
*
55-
* @return string
5645
*/
5746
public function location(): string;
5847

5948
/**
6049
* Returns body of the response.
61-
*
62-
* @return string
6350
*/
6451
public function body(): string;
6552

@@ -72,37 +59,26 @@ public function toArray(): array;
7259

7360
/**
7461
* Assert the status code of the response.
75-
*
76-
* @param int $code
77-
* @return bool
7862
*/
7963
public function isStatusCode(int $code): bool;
8064

8165
/**
8266
* Determine if response has successful status code.
83-
*
84-
* @return bool
8567
*/
8668
public function isSuccess(): bool;
8769

8870
/**
8971
* Determine if response has redirect status code.
90-
*
91-
* @return bool
9272
*/
9373
public function isRedirect(): bool;
9474

9575
/**
9676
* Determine if response has client error status code.
97-
*
98-
* @return bool
9977
*/
10078
public function isClientError(): bool;
10179

10280
/**
10381
* Determine if response has server error status code.
104-
*
105-
* @return bool
10682
*/
10783
public function isServerError(): bool;
10884
}

src/Authenticator/CookieAuthenticator.php

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,46 +19,22 @@
1919
class CookieAuthenticator implements
2020
AuthenticatorInterface
2121
{
22-
/**
23-
* @var string
24-
*/
25-
private $username = '';
26-
27-
/**
28-
* @var string
29-
*/
30-
private $password = '';
31-
32-
/**
33-
* @var string
34-
*/
35-
private $cookie = '';
36-
3722
/**
3823
* Determine is trying to authenticate.
39-
*
40-
* @var bool
4124
*/
42-
private $isAuthenticating = false;
25+
private bool $isAuthenticating = false;
4326

44-
/**
45-
* CookieAuthenticator constructor.
46-
*
47-
* @param string $username
48-
* @param string $password
49-
*/
50-
public function __construct(string $username, string $password)
51-
{
52-
$this->username = $username;
53-
$this->password = $password;
27+
private string $cookie = '';
28+
29+
public function __construct(
30+
private string $username,
31+
private string $password,
32+
) {
5433
}
5534

5635
/**
5736
* Authenticate client and returns cookie on success login.
5837
*
59-
* @param \Cog\Contracts\YouTrack\Rest\Client\Client $client
60-
* @return void
61-
*
6238
* @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException
6339
*/
6440
public function authenticate(ClientInterface $client): void
@@ -81,8 +57,6 @@ public function authenticate(ClientInterface $client): void
8157

8258
/**
8359
* Retrieve authentication token.
84-
*
85-
* @return string
8660
*/
8761
public function token(): string
8862
{

src/Authorizer/CookieAuthorizer.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,14 @@
2020
class CookieAuthorizer implements
2121
AuthorizerInterface
2222
{
23-
/**
24-
* @var \Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator
25-
*/
26-
private $authenticator;
27-
28-
/**
29-
* CookieAuthorizer constructor.
30-
*
31-
* @param \Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator $authenticator
32-
*/
33-
public function __construct(AuthenticatorInterface $authenticator)
34-
{
35-
$this->authenticator = $authenticator;
23+
public function __construct(
24+
private AuthenticatorInterface $authenticator,
25+
) {
3626
}
3727

3828
/**
3929
* Append authorization headers to REST client.
4030
*
41-
* @param \Cog\Contracts\YouTrack\Rest\Client\Client $client
42-
* @return void
43-
*
4431
* @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException
4532
*/
4633
public function appendHeadersTo(ClientInterface $client): void

src/Authorizer/TokenAuthorizer.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,13 @@
2222
class TokenAuthorizer implements
2323
AuthorizerInterface
2424
{
25-
/**
26-
* @var string
27-
*/
28-
private $token;
29-
30-
/**
31-
* TokenAuthorizer constructor.
32-
*
33-
* @param string $token
34-
*/
35-
public function __construct(string $token)
36-
{
37-
$this->token = $token;
25+
public function __construct(
26+
private string $token,
27+
) {
3828
}
3929

4030
/**
4131
* Append authorization headers to REST client.
42-
*
43-
* @param \Cog\Contracts\YouTrack\Rest\Client\Client $client
44-
* @return void
4532
*/
4633
public function appendHeadersTo(ClientInterface $client): void
4734
{

src/Client/YouTrackClient.php

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,48 +29,29 @@
2929
class YouTrackClient implements
3030
RestClientInterface
3131
{
32-
/**
33-
* HTTP Client.
34-
*
35-
* @var \Cog\Contracts\YouTrack\Rest\HttpClient\HttpClient
36-
*/
37-
private $httpClient;
38-
39-
/**
40-
* Authorization driver.
41-
*
42-
* @var \Cog\Contracts\YouTrack\Rest\Authorizer\Authorizer
43-
*/
44-
private $authorizer;
45-
4632
/**
4733
* Endpoint path prefix.
4834
*
4935
* @todo test it
50-
*
51-
* @var string
5236
*/
53-
private $endpointPathPrefix;
37+
private string $endpointPathPrefix;
5438

5539
/**
5640
* Request headers.
5741
*
5842
* @var array
5943
*/
60-
private $headers = [];
61-
62-
/**
63-
* YouTrackClient constructor.
64-
*
65-
* @param \Cog\Contracts\YouTrack\Rest\HttpClient\HttpClient $httpClient
66-
* @param \Cog\Contracts\YouTrack\Rest\Authorizer\Authorizer $authorizer
67-
* @param string $endpointPathPrefix
68-
*/
69-
public function __construct(HttpClientInterface $httpClient, AuthorizerInterface $authorizer, string $endpointPathPrefix = null)
70-
{
71-
$this->httpClient = $httpClient;
72-
$this->authorizer = $authorizer;
73-
$this->endpointPathPrefix = $endpointPathPrefix !== null ? $endpointPathPrefix : 'api';
44+
private array $headers = [];
45+
46+
public function __construct(
47+
private HttpClientInterface $httpClient,
48+
private AuthorizerInterface $authorizer,
49+
// @todo test it
50+
string | null $endpointPathPrefix = null,
51+
) {
52+
$this->endpointPathPrefix = $endpointPathPrefix !== null
53+
? $endpointPathPrefix
54+
: 'api';
7455
}
7556

7657
/**
@@ -89,7 +70,11 @@ public function __construct(HttpClientInterface $httpClient, AuthorizerInterface
8970
public function request(string $method, string $uri, array $params = [], array $options = []): ResponseInterface
9071
{
9172
try {
92-
$response = $this->httpClient->request($method, $this->buildUri($uri), $this->buildOptions($params, $options));
73+
$response = $this->httpClient->request(
74+
$method,
75+
$this->buildUri($uri),
76+
$this->buildOptions($params, $options),
77+
);
9378
} catch (HttpClientException $e) {
9479
switch ($e->getCode()) {
9580
case 401:
@@ -174,10 +159,6 @@ public function delete(string $uri, array $params = [], array $options = []): Re
174159

175160
/**
176161
* Write header value.
177-
*
178-
* @param string $key
179-
* @param string $value
180-
* @return void
181162
*/
182163
public function withHeader(string $key, string $value): void
183164
{
@@ -197,9 +178,6 @@ public function withHeaders(array $headers): void
197178

198179
/**
199180
* Build endpoint URI.
200-
*
201-
* @param string $uri
202-
* @return string
203181
*/
204182
protected function buildUri(string $uri): string
205183
{

src/HttpClient/GuzzleHttpClient.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,9 @@
2525
class GuzzleHttpClient implements
2626
HttpClientInterface
2727
{
28-
/**
29-
* GuzzleHttp client.
30-
*
31-
* @var \GuzzleHttp\ClientInterface
32-
*/
33-
protected $httpClient;
34-
35-
/**
36-
* Create a new GuzzleHttpClient instance.
37-
*
38-
* @param \GuzzleHttp\ClientInterface $httpClient
39-
*/
40-
public function __construct(ClientInterface $httpClient)
41-
{
42-
$this->httpClient = $httpClient;
28+
public function __construct(
29+
private ClientInterface $httpClient,
30+
) {
4331
}
4432

4533
/**

0 commit comments

Comments
 (0)