Skip to content

Commit c889264

Browse files
authored
Merge pull request #49 from answear/support-symfony-7
Support symfony 7
2 parents deb5f2e + aeea620 commit c889264

File tree

59 files changed

+510
-1334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+510
-1334
lines changed

.github/workflows/phpunit.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@ jobs:
1111
strategy:
1212
matrix:
1313
php-version:
14-
- "7.4"
15-
- "8.0"
16-
- "8.1"
14+
- "8.2"
1715
deps:
1816
- "normal"
19-
include:
20-
- deps: "low"
21-
php-version: "7.4"
17+
- "low"
2218

2319
steps:
2420
- name: "Checkout"

.github/workflows/static-analysis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ jobs:
1111
strategy:
1212
matrix:
1313
php-version:
14-
- "7.4"
15-
- "8.0"
16-
- "8.1"
14+
- "8.2"
1715

1816
steps:
1917
- name: "Checkout"

.php-cs-fixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
'strict_param' => false,
2222
'array_syntax' => ['syntax' => 'short'],
2323
'concat_space' => ['spacing' => 'one'],
24-
'phpdoc_align' => [],
24+
'phpdoc_align' => ['align' => 'left'],
2525
'phpdoc_summary' => false,
2626
'void_return' => false,
2727
'phpdoc_var_without_name' => false,

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,20 @@ use Answear\LuigisBoxBundle\Exception\ServiceUnavailableException;
164164
165165
try {
166166
// ... request
167-
} catch (BadRequestException $e){
167+
} catch (BadRequestException $exception){
168168
//bad request
169-
$request = $e->getRequest();
170-
$response = $e->getResponse();
171-
} catch (TooManyItemsException $e){
169+
$request = $exception->request;
170+
$response = $exception->response;
171+
} catch (TooManyItemsException $exception){
172172
//items limit reached
173-
$limit = $e->getLimit();
174-
} catch (MalformedResponseException $e){
173+
$limit = $exception->limit;
174+
} catch (MalformedResponseException $exception){
175175
//bad response
176-
$response = $e->getResponse();
177-
} catch (TooManyRequestsException $e){
176+
$response = $exception->response;
177+
} catch (TooManyRequestsException $exception){
178178
//repeat request after $retryAfter seconds
179-
$retryAfter = $e->getRetryAfterSeconds();
180-
} catch (ServiceUnavailableException $e){
179+
$retryAfter = $exception->retryAfterSeconds;
180+
} catch (ServiceUnavailableException $exception){
181181
//delay request
182182
}
183183
```

composer.json

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44
"type": "symfony-bundle",
55
"license": "MIT",
66
"require": {
7-
"php": ">=7.4|^8.0",
7+
"php": "^8.2",
88
"ext-json": "*",
9-
"marc-mabe/php-enum": "^3.0|^4.3",
10-
"webmozart/assert": "^1.3",
11-
"symfony/validator": "^5.4|^6.0",
12-
"symfony/http-kernel": "^5.4|^6.0",
13-
"guzzlehttp/guzzle": "^6.0 || ^7.0",
14-
"symfony/serializer": "^5.4|^6.0",
15-
"symfony/property-access": "^5.4|^6.0"
9+
"webmozart/assert": "^1.11",
10+
"symfony/validator": "^6.0|^7.0",
11+
"symfony/http-kernel": "^6.0|^7.0",
12+
"guzzlehttp/guzzle": "^6.0|^7.0",
13+
"symfony/serializer": "^6.0|^7.0",
14+
"symfony/property-access": "^6.0|^7.0"
1615
},
1716
"require-dev": {
1817
"roave/security-advisories": "dev-master",
19-
"phpunit/phpunit": "^9.5.23",
20-
"symfony/phpunit-bridge": "6.1.*",
21-
"phpro/grumphp": "1.13.x",
22-
"friendsofphp/php-cs-fixer": "^3.9.5",
23-
"phpstan/phpstan": "^1.10.34",
24-
"phpstan/phpstan-webmozart-assert": "^1.2.4",
25-
"matthiasnoback/symfony-config-test": "^4.3"
18+
"phpunit/phpunit": "^10.5",
19+
"symfony/phpunit-bridge": "^6.1|^7.0",
20+
"phpro/grumphp": "^2.8",
21+
"friendsofphp/php-cs-fixer": "^3.64",
22+
"phpstan/phpstan": "^1.12",
23+
"phpstan/phpstan-webmozart-assert": "^1.2",
24+
"matthiasnoback/symfony-config-test": "^5.2"
2625
},
2726
"autoload": {
2827
"psr-4": {

phpunit.xml.dist

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
44
bootstrap="./vendor/autoload.php"
55
backupGlobals="false"
6-
beStrictAboutCoversAnnotation="true"
76
beStrictAboutOutputDuringTests="true"
87
beStrictAboutTestsThatDoNotTestAnything="true"
9-
beStrictAboutTodoAnnotatedTests="true"
108
colors="true"
11-
convertErrorsToExceptions="true"
12-
convertNoticesToExceptions="true"
13-
convertWarningsToExceptions="true"
14-
verbose="true"
9+
cacheDirectory=".phpunit.cache"
10+
beStrictAboutCoverageMetadata="true"
1511
>
1612
<php>
1713
<ini name="error_reporting" value="-1"/>
1814
</php>
19-
2015
<testsuites>
2116
<testsuite name="Answear LuigisBox Test Suite">
2217
<directory>./tests</directory>
2318
</testsuite>
2419
</testsuites>
25-
26-
<listeners>
27-
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
28-
</listeners>
2920
</phpunit>

src/LuigisBoxBundle/DTO/ConfigDTO.php

Lines changed: 11 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -5,100 +5,24 @@
55
namespace Answear\LuigisBoxBundle\DTO;
66

77
use Answear\LuigisBoxBundle\DependencyInjection\Configuration;
8+
use Webmozart\Assert\Assert;
89

9-
class ConfigDTO
10+
readonly class ConfigDTO
1011
{
1112
private const MAX_SEARCH_CACHE_TTL = 300;
1213

13-
/**
14-
* @var string
15-
*/
16-
private $host;
17-
18-
/**
19-
* @var string
20-
*/
21-
private $publicKey;
22-
23-
/**
24-
* @var string
25-
*/
26-
private $privateKey;
27-
28-
/**
29-
* @var float
30-
*/
31-
private $connectionTimeout;
32-
33-
/**
34-
* @var float
35-
*/
36-
private $requestTimeout;
37-
38-
/**
39-
* @var float
40-
*/
41-
private $searchTimeout;
42-
43-
/**
44-
* @var int
45-
*/
46-
private $searchCacheTtl;
14+
public int $searchCacheTtl;
4715

4816
public function __construct(
49-
string $publicKey,
50-
string $privateKey,
51-
string $host = Configuration::HOST,
52-
float $connectionTimeout = Configuration::CONNECTION_TIMEOUT,
53-
float $requestTimeout = Configuration::REQUEST_TIMEOUT,
54-
float $searchTimeout = Configuration::SEARCH_TIMEOUT,
55-
int $searchCacheTtl = Configuration::SEARCH_CACHE_TIMEOUT
17+
public string $publicKey,
18+
public string $privateKey,
19+
public string $host = Configuration::HOST,
20+
public float $connectionTimeout = Configuration::CONNECTION_TIMEOUT,
21+
public float $requestTimeout = Configuration::REQUEST_TIMEOUT,
22+
public float $searchTimeout = Configuration::SEARCH_TIMEOUT,
23+
int $searchCacheTtl = Configuration::SEARCH_CACHE_TIMEOUT,
5624
) {
57-
if ($searchCacheTtl < 0) {
58-
throw new \InvalidArgumentException('searchCacheTtl cannot be negative.');
59-
}
60-
61-
$this->host = $host;
62-
$this->publicKey = $publicKey;
63-
$this->privateKey = $privateKey;
64-
$this->connectionTimeout = $connectionTimeout;
65-
$this->requestTimeout = $requestTimeout;
66-
$this->searchTimeout = $searchTimeout;
25+
Assert::greaterThanEq($searchCacheTtl, 0, 'searchCacheTtl cannot be negative.');
6726
$this->searchCacheTtl = min($searchCacheTtl, self::MAX_SEARCH_CACHE_TTL);
6827
}
69-
70-
public function getHost(): string
71-
{
72-
return $this->host;
73-
}
74-
75-
public function getPublicKey(): string
76-
{
77-
return $this->publicKey;
78-
}
79-
80-
public function getPrivateKey(): string
81-
{
82-
return $this->privateKey;
83-
}
84-
85-
public function getConnectionTimeout(): float
86-
{
87-
return $this->connectionTimeout;
88-
}
89-
90-
public function getRequestTimeout(): float
91-
{
92-
return $this->requestTimeout;
93-
}
94-
95-
public function getSearchTimeout(): float
96-
{
97-
return $this->searchTimeout;
98-
}
99-
100-
public function getSearchCacheTtl(): int
101-
{
102-
return $this->searchCacheTtl;
103-
}
10428
}

src/LuigisBoxBundle/Exception/ApiErrorException.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,10 @@
88

99
class ApiErrorException extends \RuntimeException
1010
{
11-
/**
12-
* @var Request
13-
*/
14-
private $request;
15-
16-
public function __construct(string $message, Request $request)
17-
{
11+
public function __construct(
12+
string $message,
13+
public readonly Request $request,
14+
) {
1815
parent::__construct($message);
19-
20-
$this->request = $request;
21-
}
22-
23-
public function getRequest(): Request
24-
{
25-
return $this->request;
2616
}
2717
}

src/LuigisBoxBundle/Exception/BadRequestException.php

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,10 @@
99

1010
class BadRequestException extends \RuntimeException
1111
{
12-
/**
13-
* @var ResponseInterface
14-
*/
15-
private $response;
16-
17-
/**
18-
* @var Request
19-
*/
20-
private $request;
21-
22-
public function __construct(ResponseInterface $response, Request $request)
23-
{
12+
public function __construct(
13+
public readonly ResponseInterface $response,
14+
public readonly Request $request,
15+
) {
2416
parent::__construct('Bad request.');
25-
26-
$this->response = $response;
27-
$this->request = $request;
28-
}
29-
30-
public function getResponse(): ResponseInterface
31-
{
32-
return $this->response;
33-
}
34-
35-
public function getRequest(): Request
36-
{
37-
return $this->request;
3817
}
3918
}

src/LuigisBoxBundle/Exception/MalformedResponseException.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,12 @@
99

1010
class MalformedResponseException extends \RuntimeException
1111
{
12-
/**
13-
* @var ResponseInterface
14-
*/
15-
private $response;
16-
17-
/**
18-
* @var Request
19-
*/
20-
private $request;
21-
22-
public function __construct(string $message, ResponseInterface $response, Request $request, ?\Throwable $previous = null)
23-
{
12+
public function __construct(
13+
string $message,
14+
public readonly ResponseInterface $response,
15+
public readonly Request $request,
16+
?\Throwable $previous = null,
17+
) {
2418
parent::__construct($message, 0, $previous);
25-
26-
$this->response = $response;
27-
$this->request = $request;
28-
}
29-
30-
public function getResponse(): ResponseInterface
31-
{
32-
return $this->response;
33-
}
34-
35-
public function getRequest(): Request
36-
{
37-
return $this->request;
3819
}
3920
}

0 commit comments

Comments
 (0)