Skip to content

Commit 30af009

Browse files
refactor: drop support for php 7.4 and optimize code (#5)
1 parent 9175ac6 commit 30af009

15 files changed

+41
-100
lines changed

.github/workflows/phpunit.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ jobs:
1111
os:
1212
- ubuntu-latest
1313
php:
14-
- 7.4
1514
- 8.0
1615
dependency-version: [prefer-lowest, prefer-stable]
1716

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## v1.1.0 - 2021-07-XX
4+
5+
- drop support for php 7.4
6+
- some code optimizations
7+
38
## v1.0.1 - 2021-07-05
49

510
- remove `illuminate/support` as dependency

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "MIT",
1010
"homepage": "https://github.com/dogado-group/json-api-client",
1111
"require": {
12-
"php": "^7.4 || ^8.0",
12+
"php": "^8.0",
1313
"ext-json": "*",
1414
"dogado/json-api-common": "^1.0",
1515
"psr/http-factory": "^1.0",

src/Action/AbstractAction.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,15 @@
1414

1515
abstract class AbstractAction implements ActionInterface
1616
{
17-
protected JsonApiClient $client;
18-
protected RequestFactoryInterface $requestFactory;
19-
protected UriFactoryInterface $uriFactory;
20-
protected ResponseValidator $responseValidator;
21-
2217
/** @var callable[] */
2318
protected array $preExecutionCallStack = [];
2419

2520
public function __construct(
26-
JsonApiClient $client,
27-
RequestFactoryInterface $requestFactory,
28-
UriFactoryInterface $uriFactory,
29-
ResponseValidator $responseValidator
21+
protected JsonApiClient $client,
22+
protected RequestFactoryInterface $requestFactory,
23+
protected UriFactoryInterface $uriFactory,
24+
protected ResponseValidator $responseValidator
3025
) {
31-
$this->client = $client;
32-
$this->requestFactory = $requestFactory;
33-
$this->uriFactory = $uriFactory;
34-
$this->responseValidator = $responseValidator;
3526
}
3627

3728
abstract public function execute(): ResponseInterface;

src/Action/FiltersResource.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ trait FiltersResource
1212

1313
/**
1414
* @param string|array $filterOrKey
15-
* @param mixed $value
16-
* @return $this
1715
*/
18-
public function filter($filterOrKey, $value = null): self
16+
public function filter(mixed $filterOrKey, mixed $value = null): self
1917
{
2018
$this->beforeSend('filter', function (RequestInterface $request) {
2119
$this->applyFilter($request);

src/Action/PaginatesResource.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ trait PaginatesResource
1212

1313
/**
1414
* @param string|array $paginationOrKey
15-
* @param mixed $value
1615
*/
17-
public function pagination($paginationOrKey, $value = null): self
16+
public function pagination(mixed $paginationOrKey, mixed $value = null): self
1817
{
1918
$this->beforeSend('paginate', function (RequestInterface $request) {
2019
$this->applyPagination($request);

src/Action/SortsResource.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ trait SortsResource
1212

1313
/**
1414
* @param string|array $sortOrKey
15-
* @param mixed $direction
16-
* @return $this
1715
*/
18-
public function sort($sortOrKey, $direction = null): self
16+
public function sort(mixed $sortOrKey, mixed $direction = null): self
1917
{
2018
$this->beforeSend('sort', function (RequestInterface $request) {
2119
$this->applySorting($request);

src/Exception/ResponseException.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ class ResponseException extends Exception
1717
{
1818
public const CODE_UNSUCCESSFUL_HTTP_STATUS = 100;
1919

20-
protected RequestInterface $request;
21-
protected PsrRequestInterface $psrRequest;
22-
protected ResponseInterface $response;
23-
protected PsrResponseInterface $psrResponse;
24-
2520
public static function unsuccessfulHttpStatusReturned(
2621
RequestInterface $request,
2722
PsrRequestInterface $psrRequest,
@@ -41,10 +36,10 @@ public static function unsuccessfulHttpStatusReturned(
4136
public function __construct(
4237
string $message,
4338
int $code,
44-
RequestInterface $request,
45-
PsrRequestInterface $psrRequest,
46-
ResponseInterface $response,
47-
PsrResponseInterface $psrResponse,
39+
protected RequestInterface $request,
40+
protected PsrRequestInterface $psrRequest,
41+
protected ResponseInterface $response,
42+
protected PsrResponseInterface $psrResponse,
4843
Throwable $previous = null
4944
) {
5045
$document = $response->document();
@@ -55,10 +50,6 @@ public function __construct(
5550
}
5651

5752
parent::__construct($message, $code, $previous);
58-
$this->request = $request;
59-
$this->psrRequest = $psrRequest;
60-
$this->response = $response;
61-
$this->psrResponse = $psrResponse;
6253
}
6354

6455
public function request(): RequestInterface

src/Factory/RequestFactory.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212

1313
class RequestFactory implements RequestFactoryInterface
1414
{
15-
protected UriInterface $baseUrl;
16-
17-
public function __construct(UriInterface $baseUrl)
15+
public function __construct(protected UriInterface $baseUrl)
1816
{
19-
$this->baseUrl = $baseUrl;
2017
}
2118

2219
/**

src/JsonApiClient.php

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,14 @@
1919

2020
class JsonApiClient
2121
{
22-
protected ClientInterface $httpClient;
23-
protected RequestFactoryInterface $requestFactory;
24-
protected StreamFactoryInterface $streamFactory;
25-
protected DocumentSerializerInterface $serializer;
26-
protected ResponseFactoryInterface $responseFactory;
27-
protected ?AuthenticationMiddlewareInterface $authMiddleware;
28-
2922
public function __construct(
30-
ClientInterface $httpClient,
31-
RequestFactoryInterface $requestFactory,
32-
StreamFactoryInterface $streamFactory,
33-
DocumentSerializerInterface $serializer,
34-
ResponseFactoryInterface $responseFactory,
35-
?AuthenticationMiddlewareInterface $authMiddleware = null
23+
protected ClientInterface $httpClient,
24+
protected RequestFactoryInterface $requestFactory,
25+
protected StreamFactoryInterface $streamFactory,
26+
protected DocumentSerializerInterface $serializer,
27+
protected ResponseFactoryInterface $responseFactory,
28+
protected ?AuthenticationMiddlewareInterface $authMiddleware = null
3629
) {
37-
$this->httpClient = $httpClient;
38-
$this->requestFactory = $requestFactory;
39-
$this->streamFactory = $streamFactory;
40-
$this->serializer = $serializer;
41-
$this->responseFactory = $responseFactory;
42-
$this->authMiddleware = $authMiddleware;
4330
}
4431

4532
/**

src/Model/BasicCredentials.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
*/
1010
class BasicCredentials
1111
{
12-
public string $username;
13-
public string $password;
14-
15-
public function __construct(string $username, string $password)
16-
{
17-
$this->username = $username;
18-
$this->password = $password;
12+
public function __construct(
13+
public string $username,
14+
public string $password
15+
) {
1916
}
2017
}

src/Model/OAuth2Credentials.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88

99
class OAuth2Credentials
1010
{
11-
public string $tokenType;
12-
public string $accessToken;
13-
public ?DateTimeInterface $expiresAt;
14-
15-
public function __construct(string $tokenType, string $accessToken, DateTimeInterface $expiresAt = null)
16-
{
17-
$this->tokenType = $tokenType;
18-
$this->accessToken = $accessToken;
19-
$this->expiresAt = $expiresAt;
11+
public function __construct(
12+
public string $tokenType,
13+
public string $accessToken,
14+
public ?DateTimeInterface $expiresAt = null
15+
) {
2016
}
2117

2218
public function isExpired(): bool

src/Response/Response.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ class Response implements ResponseInterface
1414
{
1515
private int $status;
1616
private KeyValueCollectionInterface $headers;
17-
private ?DocumentInterface $document;
18-
protected ?PsrResponseInterface $psrResponse;
1917

2018
public function __construct(
21-
PsrResponseInterface $psrResponse,
22-
?DocumentInterface $document = null
19+
protected PsrResponseInterface $psrResponse,
20+
private ?DocumentInterface $document = null
2321
) {
2422
$this->status = $psrResponse->getStatusCode();
2523
$this->headers = new KeyValueCollection();
@@ -29,9 +27,6 @@ public function __construct(
2927
}
3028
$this->headers->set($header, $value);
3129
}
32-
33-
$this->document = $document;
34-
$this->psrResponse = $psrResponse;
3530
}
3631

3732
public function status(): int

src/Response/ResponseFactory.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515

1616
class ResponseFactory implements ResponseFactoryInterface
1717
{
18-
protected DocumentDeserializerInterface $deserializer;
19-
20-
public function __construct(DocumentDeserializerInterface $deserializer)
18+
public function __construct(protected DocumentDeserializerInterface $deserializer)
2119
{
22-
$this->deserializer = $deserializer;
2320
}
2421

2522
/**
@@ -37,7 +34,7 @@ public function createResponse(
3734
if ($psrResponse->getStatusCode() >= 400) {
3835
try {
3936
$responseDocument = $this->createResponseBody($responseBody);
40-
} catch (BadResponseException $e) {
37+
} catch (BadResponseException) {
4138
$responseDocument = null;
4239
}
4340

src/Service/OAuth2Authenticator.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,12 @@
1515

1616
class OAuth2Authenticator
1717
{
18-
protected ClientInterface $httpClient;
19-
protected RequestFactoryInterface $requestFactory;
20-
protected StreamFactoryInterface $streamFactory;
21-
protected CredentialFactoryInterface $authStorageFactory;
22-
2318
public function __construct(
24-
ClientInterface $httpClient,
25-
RequestFactoryInterface $requestFactory,
26-
StreamFactoryInterface $streamFactory,
27-
CredentialFactoryInterface $authStorageFactory
19+
protected ClientInterface $httpClient,
20+
protected RequestFactoryInterface $requestFactory,
21+
protected StreamFactoryInterface $streamFactory,
22+
protected CredentialFactoryInterface $authStorageFactory
2823
) {
29-
$this->httpClient = $httpClient;
30-
$this->requestFactory = $requestFactory;
31-
$this->streamFactory = $streamFactory;
32-
$this->authStorageFactory = $authStorageFactory;
3324
}
3425

3526
/**

0 commit comments

Comments
 (0)