diff --git a/composer.json b/composer.json index a12ee58..05f7f3a 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "docs": "https://github.com/cybercog/youtrack-rest-php/wiki" }, "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", "guzzlehttp/guzzle": "^6.2" }, diff --git a/contracts/Authenticator/Authenticator.php b/contracts/Authenticator/Authenticator.php index 662836c..b8cd702 100644 --- a/contracts/Authenticator/Authenticator.php +++ b/contracts/Authenticator/Authenticator.php @@ -20,17 +20,12 @@ interface Authenticator /** * Authenticate API Client. * - * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client - * @return void - * * @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException */ public function authenticate(ClientInterface $client): void; /** * Retrieve authentication token. - * - * @return string */ public function token(): string; } diff --git a/contracts/Authorizer/Authorizer.php b/contracts/Authorizer/Authorizer.php index e64c720..5fb8207 100644 --- a/contracts/Authorizer/Authorizer.php +++ b/contracts/Authorizer/Authorizer.php @@ -19,9 +19,6 @@ interface Authorizer { /** * Append authorization headers to REST client. - * - * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client - * @return void */ public function appendHeadersTo(ClientInterface $client): void; } diff --git a/contracts/Client/Client.php b/contracts/Client/Client.php index 5cd576b..358777f 100644 --- a/contracts/Client/Client.php +++ b/contracts/Client/Client.php @@ -95,10 +95,6 @@ public function delete(string $uri, array $params = [], array $options = []): Re /** * Write header value. - * - * @param string $key - * @param string $value - * @return void */ public function withHeader(string $key, string $value): void; diff --git a/contracts/Response/Response.php b/contracts/Response/Response.php index f54e85b..f330ea0 100644 --- a/contracts/Response/Response.php +++ b/contracts/Response/Response.php @@ -19,8 +19,6 @@ interface Response { /** * Returns original HTTP client response. - * - * @return \Psr\Http\Message\ResponseInterface */ public function httpResponse(): PsrResponseInterface; @@ -29,37 +27,26 @@ public function httpResponse(): PsrResponseInterface; * * The status code is a 3-digit integer result code of the server's attempt * to understand and satisfy the request. - * - * @return int */ public function statusCode(): int; /** * Retrieves a comma-separated string of the values for a single header. - * - * @param string $header - * @return string */ public function header(string $header): string; /** * Transform response cookie headers to string. - * - * @return string */ public function cookie(): string; /** * Returns response location header. - * - * @return string */ public function location(): string; /** * Returns body of the response. - * - * @return string */ public function body(): string; @@ -72,37 +59,26 @@ public function toArray(): array; /** * Assert the status code of the response. - * - * @param int $code - * @return bool */ public function isStatusCode(int $code): bool; /** * Determine if response has successful status code. - * - * @return bool */ public function isSuccess(): bool; /** * Determine if response has redirect status code. - * - * @return bool */ public function isRedirect(): bool; /** * Determine if response has client error status code. - * - * @return bool */ public function isClientError(): bool; /** * Determine if response has server error status code. - * - * @return bool */ public function isServerError(): bool; } diff --git a/src/Authenticator/CookieAuthenticator.php b/src/Authenticator/CookieAuthenticator.php index a5b4b4d..3dd5d82 100644 --- a/src/Authenticator/CookieAuthenticator.php +++ b/src/Authenticator/CookieAuthenticator.php @@ -19,46 +19,22 @@ class CookieAuthenticator implements AuthenticatorInterface { - /** - * @var string - */ - private $username = ''; - - /** - * @var string - */ - private $password = ''; - - /** - * @var string - */ - private $cookie = ''; - /** * Determine is trying to authenticate. - * - * @var bool */ - private $isAuthenticating = false; + private bool $isAuthenticating = false; - /** - * CookieAuthenticator constructor. - * - * @param string $username - * @param string $password - */ - public function __construct(string $username, string $password) - { - $this->username = $username; - $this->password = $password; + private string $cookie = ''; + + public function __construct( + private string $username, + private string $password, + ) { } /** * Authenticate client and returns cookie on success login. * - * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client - * @return void - * * @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException */ public function authenticate(ClientInterface $client): void @@ -81,8 +57,6 @@ public function authenticate(ClientInterface $client): void /** * Retrieve authentication token. - * - * @return string */ public function token(): string { diff --git a/src/Authorizer/CookieAuthorizer.php b/src/Authorizer/CookieAuthorizer.php index c91247b..0deb55e 100644 --- a/src/Authorizer/CookieAuthorizer.php +++ b/src/Authorizer/CookieAuthorizer.php @@ -20,27 +20,14 @@ class CookieAuthorizer implements AuthorizerInterface { - /** - * @var \Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator - */ - private $authenticator; - - /** - * CookieAuthorizer constructor. - * - * @param \Cog\Contracts\YouTrack\Rest\Authenticator\Authenticator $authenticator - */ - public function __construct(AuthenticatorInterface $authenticator) - { - $this->authenticator = $authenticator; + public function __construct( + private AuthenticatorInterface $authenticator, + ) { } /** * Append authorization headers to REST client. * - * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client - * @return void - * * @throws \Cog\Contracts\YouTrack\Rest\Authenticator\Exceptions\AuthenticationException */ public function appendHeadersTo(ClientInterface $client): void diff --git a/src/Authorizer/TokenAuthorizer.php b/src/Authorizer/TokenAuthorizer.php index 5c5f1c1..d79daef 100644 --- a/src/Authorizer/TokenAuthorizer.php +++ b/src/Authorizer/TokenAuthorizer.php @@ -22,26 +22,13 @@ class TokenAuthorizer implements AuthorizerInterface { - /** - * @var string - */ - private $token; - - /** - * TokenAuthorizer constructor. - * - * @param string $token - */ - public function __construct(string $token) - { - $this->token = $token; + public function __construct( + private string $token, + ) { } /** * Append authorization headers to REST client. - * - * @param \Cog\Contracts\YouTrack\Rest\Client\Client $client - * @return void */ public function appendHeadersTo(ClientInterface $client): void { diff --git a/src/Client/YouTrackClient.php b/src/Client/YouTrackClient.php index 6f8003b..e606381 100644 --- a/src/Client/YouTrackClient.php +++ b/src/Client/YouTrackClient.php @@ -29,48 +29,29 @@ class YouTrackClient implements RestClientInterface { - /** - * HTTP Client. - * - * @var \Cog\Contracts\YouTrack\Rest\HttpClient\HttpClient - */ - private $httpClient; - - /** - * Authorization driver. - * - * @var \Cog\Contracts\YouTrack\Rest\Authorizer\Authorizer - */ - private $authorizer; - /** * Endpoint path prefix. * * @todo test it - * - * @var string */ - private $endpointPathPrefix; + private string $endpointPathPrefix; /** * Request headers. * * @var array */ - private $headers = []; - - /** - * YouTrackClient constructor. - * - * @param \Cog\Contracts\YouTrack\Rest\HttpClient\HttpClient $httpClient - * @param \Cog\Contracts\YouTrack\Rest\Authorizer\Authorizer $authorizer - * @param string $endpointPathPrefix - */ - public function __construct(HttpClientInterface $httpClient, AuthorizerInterface $authorizer, string $endpointPathPrefix = null) - { - $this->httpClient = $httpClient; - $this->authorizer = $authorizer; - $this->endpointPathPrefix = $endpointPathPrefix !== null ? $endpointPathPrefix : 'api'; + private array $headers = []; + + public function __construct( + private HttpClientInterface $httpClient, + private AuthorizerInterface $authorizer, + // @todo test it + string | null $endpointPathPrefix = null, + ) { + $this->endpointPathPrefix = $endpointPathPrefix !== null + ? $endpointPathPrefix + : 'api'; } /** @@ -89,7 +70,11 @@ public function __construct(HttpClientInterface $httpClient, AuthorizerInterface public function request(string $method, string $uri, array $params = [], array $options = []): ResponseInterface { try { - $response = $this->httpClient->request($method, $this->buildUri($uri), $this->buildOptions($params, $options)); + $response = $this->httpClient->request( + $method, + $this->buildUri($uri), + $this->buildOptions($params, $options), + ); } catch (HttpClientException $e) { switch ($e->getCode()) { case 401: @@ -174,10 +159,6 @@ public function delete(string $uri, array $params = [], array $options = []): Re /** * Write header value. - * - * @param string $key - * @param string $value - * @return void */ public function withHeader(string $key, string $value): void { @@ -197,9 +178,6 @@ public function withHeaders(array $headers): void /** * Build endpoint URI. - * - * @param string $uri - * @return string */ protected function buildUri(string $uri): string { diff --git a/src/HttpClient/GuzzleHttpClient.php b/src/HttpClient/GuzzleHttpClient.php index 023cd28..6f9c0a6 100644 --- a/src/HttpClient/GuzzleHttpClient.php +++ b/src/HttpClient/GuzzleHttpClient.php @@ -25,21 +25,9 @@ class GuzzleHttpClient implements HttpClientInterface { - /** - * GuzzleHttp client. - * - * @var \GuzzleHttp\ClientInterface - */ - protected $httpClient; - - /** - * Create a new GuzzleHttpClient instance. - * - * @param \GuzzleHttp\ClientInterface $httpClient - */ - public function __construct(ClientInterface $httpClient) - { - $this->httpClient = $httpClient; + public function __construct( + private ClientInterface $httpClient, + ) { } /** diff --git a/src/Response/YouTrackResponse.php b/src/Response/YouTrackResponse.php index b3aa6b0..90b8a4e 100644 --- a/src/Response/YouTrackResponse.php +++ b/src/Response/YouTrackResponse.php @@ -19,27 +19,13 @@ class YouTrackResponse implements ResponseInterface { - /** - * Original HTTP client response. - * - * @var \Psr\Http\Message\ResponseInterface - */ - private $response; - - /** - * YouTrackResponse constructor. - * - * @param \Psr\Http\Message\ResponseInterface $response - */ - public function __construct(PsrResponseInterface $response) - { - $this->response = $response; + public function __construct( + private PsrResponseInterface $response, + ) { } /** * Returns original HTTP client response. - * - * @return \Psr\Http\Message\ResponseInterface */ public function httpResponse(): PsrResponseInterface { @@ -51,8 +37,6 @@ public function httpResponse(): PsrResponseInterface * * The status code is a 3-digit integer result code of the server's attempt * to understand and satisfy the request. - * - * @return int */ public function statusCode(): int { @@ -61,9 +45,6 @@ public function statusCode(): int /** * Retrieves a comma-separated string of the values for a single header. - * - * @param string $header - * @return string */ public function header(string $header): string { @@ -72,8 +53,6 @@ public function header(string $header): string /** * Transform response cookie headers to string. - * - * @return string */ public function cookie(): string { @@ -82,8 +61,6 @@ public function cookie(): string /** * Returns response location header. - * - * @return string */ public function location(): string { @@ -92,12 +69,10 @@ public function location(): string /** * Returns body of the response. - * - * @return string */ public function body(): string { - return (string) $this->response->getBody(); + return (string)$this->response->getBody(); } /** @@ -112,9 +87,6 @@ public function toArray(): array /** * Assert the status code of the response. - * - * @param int $code - * @return bool */ public function isStatusCode(int $code): bool { @@ -123,8 +95,6 @@ public function isStatusCode(int $code): bool /** * Determine if response has successful status code. - * - * @return bool */ public function isSuccess(): bool { @@ -133,8 +103,6 @@ public function isSuccess(): bool /** * Determine if response has redirect status code. - * - * @return bool */ public function isRedirect(): bool { @@ -143,8 +111,6 @@ public function isRedirect(): bool /** * Determine if response has client error status code. - * - * @return bool */ public function isClientError(): bool { @@ -153,8 +119,6 @@ public function isClientError(): bool /** * Determine if response has server error status code. - * - * @return bool */ public function isServerError(): bool {