Skip to content

Commit c6c246f

Browse files
authored
[2.x] Min PHP version 8.1, Symfony 6.4 / 7.1+ (#463)
* ⬆️ [#458] Update min PHP version to 8.1 * 📦 Add typehint to parameter in private method * 📦 [#458] Update min Symfony version to `^6.4 || ^7.1` * 📦 Hint about always non-null return type * 📦 Avoid deprecated DI extension class * 📦 Fix property type in phpdoc * 📦 Avoid invalid argument - cast possible float to the integer * 📦 [#458] Introduce property types, use PHP 8.1 features (CPP, short arrow function, readonly properties, etc) * 📦 [#458] Switch to `php-cs-fixer-ga` 3.26 and run it * 📦 Require phpunit 9 because `simple-phpunit` is not compatible with phpunit 10 and `matthiasnoback/symfony-config-test` triggers installation of phpunit 10 * 💄 Multiline constructor parameters * 📦 Safe property types - property can be uninitialized. Explicitly mention possible return null * 📦 Use native union type for parameter * 📦 Enforce installing `matthiasnoback/symfony-config-test` to fix CI for lowest deps
1 parent 734a76e commit c6c246f

Some content is hidden

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

42 files changed

+282
-770
lines changed

Diff for: .github/workflows/continuous-integration.yml

+10-19
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,12 @@ jobs:
2222
include:
2323
# Minimum supported Symfony version and lowest PHP version
2424
- dependencies: "php-http/guzzle7-adapter php-http/discovery:^1.12"
25-
php-version: "7.3"
25+
php-version: "8.1"
2626
dependency-versions: "lowest"
2727
symfony-deprecations-helper: "weak"
2828
stability: "stable"
2929

3030
# Test the latest stable release
31-
- dependencies: "php-http/guzzle7-adapter php-http/vcr-plugin:^1.0@dev"
32-
php-version: "7.3"
33-
symfony-deprecations-helper: "weak"
34-
- dependencies: "php-http/guzzle6-adapter"
35-
php-version: "7.4"
36-
symfony-deprecations-helper: "weak"
37-
- dependencies: "php-http/guzzle7-adapter"
38-
php-version: "8.0"
39-
symfony-deprecations-helper: "weak"
4031
- dependencies: "php-http/guzzle7-adapter"
4132
php-version: "8.1"
4233
symfony-deprecations-helper: "weak"
@@ -49,7 +40,7 @@ jobs:
4940

5041
# Test with httplug 2.x clients
5142
- dependencies: "php-http/guzzle7-adapter php-http/curl-client:^2.0.0 php-http/vcr-plugin:^1.0@dev php-http/socket-client:^2.0"
52-
php-version: "7.3"
43+
php-version: "8.1"
5344
symfony-deprecations-helper: "weak"
5445

5546
# Latest commit to master
@@ -63,17 +54,17 @@ jobs:
6354
symfony-deprecations-helper: "weak"
6455

6556
# Test maintained versions of Symfony
66-
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^5.4"
67-
symfony-require: "5.4.*"
68-
php-version: "7.3"
57+
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^6.4"
58+
symfony-require: "6.4.*"
59+
php-version: "8.1"
6960
symfony-deprecations-helper: "weak"
70-
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^6.0"
71-
symfony-require: "6.3.*"
61+
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^6.4"
62+
symfony-require: "6.4.*"
7263
php-version: "8.2"
7364
symfony-deprecations-helper: "weak"
74-
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^6.0"
75-
symfony-require: "6.4.*"
76-
php-version: "8.1"
65+
- dependencies: "php-http/guzzle7-adapter symfony/http-client:^7.1"
66+
symfony-require: "7.1.*"
67+
php-version: "8.2"
7768
symfony-deprecations-helper: "weak"
7869

7970
steps:

Diff for: .github/workflows/php-cs-fixer.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
- name: "Checkout"
1818
uses: "actions/checkout@v3"
1919
- name: "PHP-CS-Fixer"
20-
uses: "docker://oskarstark/php-cs-fixer-ga:2.19.0"
20+
uses: "docker://oskarstark/php-cs-fixer-ga:3.26.0"
2121
with:
2222
args: --diff --dry-run

Diff for: .php_cs.dist renamed to .php-cs-fixer.dist.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
<?php
22

3-
$finder = PhpCsFixer\Finder::create()
3+
$finder = (new PhpCsFixer\Finder())
44
->exclude('src/Resources')
55
->exclude('vendor')
66
->in(__DIR__)
77
;
88

9-
return PhpCsFixer\Config::create()
9+
return (new PhpCsFixer\Config())
1010
->setRiskyAllowed(true)
1111
->setRules([
1212
'@Symfony' => true,
1313
'array_syntax' => ['syntax' => 'short'],
1414
'declare_strict_types' => true,
1515
'single_line_throw' => false,
16+
'nullable_type_declaration_for_default_null_value' => true,
1617
'visibility_required' => [
1718
'elements' => [
1819
'const',

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
55
# Version 2
66

77
# 2.0.0 - (unreleased)
8+
- Increased min PHP version to 8.1
89
- Fixed a deprecation when creating a `HttpMethodsClient` via `http_methods_client: true`. Only PSR-17 factories are now passed as constructor arguments.
910
- Changed the default stream factory argument for the cache plugin. This now requires a PSR-17 StreamFactoryInterface instance.
1011
- Creating a client using the `BuzzFactory` no longer accepts `verify_peer` and `verify_host` config options. Only a boolean `verify` flag is accepted, covering both previous options.

Diff for: composer.json

+17-15
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
}
2626
],
2727
"require": {
28-
"php": "^7.3 || ^8.0",
28+
"php": "^8.1",
2929
"php-http/client-common": "^2.0",
3030
"php-http/client-implementation": "^1.0",
3131
"php-http/discovery": "^1.14",
@@ -35,11 +35,11 @@
3535
"php-http/stopwatch-plugin": "^1.2",
3636
"psr/http-factory-implementation": "^1.0",
3737
"psr/http-message": "^1.0 || ^2.0",
38-
"symfony/config": "^5.4 || ^6.0 || ^7.0",
39-
"symfony/dependency-injection": "^5.4 || ^6.0 || ^7.0",
40-
"symfony/event-dispatcher": "^5.4 || ^6.0 || ^7.0",
41-
"symfony/http-kernel": "^5.4 || ^6.0 || ^7.0",
42-
"symfony/options-resolver": "^5.4 || ^6.0 || ^7.0"
38+
"symfony/config": "^6.4 || ^7.1",
39+
"symfony/dependency-injection": "^6.4 || ^7.1",
40+
"symfony/event-dispatcher": "^6.4 || ^7.1",
41+
"symfony/http-kernel": "^6.4 || ^7.1",
42+
"symfony/options-resolver": "^6.4 || ^7.1"
4343
},
4444
"conflict": {
4545
"php-http/guzzle6-adapter": "<1.1",
@@ -51,21 +51,23 @@
5151
},
5252
"require-dev": {
5353
"guzzlehttp/psr7": "^1.7 || ^2.0",
54+
"matthiasnoback/symfony-config-test": "^5.2",
5455
"matthiasnoback/symfony-dependency-injection-test": "^4.0 || ^5.0",
5556
"nyholm/nsa": "^1.1",
5657
"nyholm/psr7": "^1.2.1",
5758
"php-http/cache-plugin": "^1.7",
5859
"php-http/mock-client": "^1.2",
5960
"php-http/promise": "^1.0",
60-
"symfony/browser-kit": "^5.4 || ^6.0 || ^7.0",
61-
"symfony/cache": "^5.4 || ^6.0 || ^7.0",
62-
"symfony/dom-crawler": "^5.4 || ^6.0 || ^7.0",
63-
"symfony/framework-bundle": "^5.4 || ^6.0 || ^7.0",
64-
"symfony/http-foundation": "^5.4 || ^6.0 || ^7.0",
65-
"symfony/phpunit-bridge": "^7.0.3",
66-
"symfony/stopwatch": "^5.4 || ^6.0 || ^7.0",
67-
"symfony/twig-bundle": "^5.4 || ^6.0 || ^7.0",
68-
"symfony/web-profiler-bundle": "^5.4 || ^6.0 || ^7.0",
61+
"phpunit/phpunit": "^9",
62+
"symfony/browser-kit": "^6.4 || ^7.1",
63+
"symfony/cache": "^6.4 || ^7.1",
64+
"symfony/dom-crawler": "^6.4 || ^7.1",
65+
"symfony/framework-bundle": "^6.4 || ^7.1",
66+
"symfony/http-foundation": "^6.4 || ^7.1",
67+
"symfony/phpunit-bridge": "^7.1",
68+
"symfony/stopwatch": "^6.4 || ^7.1",
69+
"symfony/twig-bundle": "^6.4 || ^7.1",
70+
"symfony/web-profiler-bundle": "^6.4 || ^7.1",
6971
"twig/twig": "^1.41 || ^2.10 || ^3.0"
7072
},
7173
"suggest": {

Diff for: src/ClientFactory/AutoDiscoveryFactory.php

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
*/
1414
class AutoDiscoveryFactory implements ClientFactory
1515
{
16-
/**
17-
* {@inheritdoc}
18-
*/
1916
public function createClient(array $config = [])
2017
{
2118
return Psr18ClientDiscovery::find();

Diff for: src/ClientFactory/BuzzFactory.php

+4-13
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,10 @@
1313
*/
1414
class BuzzFactory implements ClientFactory
1515
{
16-
/**
17-
* @var ResponseFactoryInterface
18-
*/
19-
private $responseFactory;
20-
21-
public function __construct(ResponseFactoryInterface $responseFactory)
16+
public function __construct(private readonly ResponseFactoryInterface $responseFactory)
2217
{
23-
$this->responseFactory = $responseFactory;
2418
}
2519

26-
/**
27-
* {@inheritdoc}
28-
*/
2920
public function createClient(array $config = [])
3021
{
3122
if (!class_exists('Buzz\Client\FileGetContents')) {
@@ -43,9 +34,9 @@ private function getOptions(array $config = [])
4334
$resolver = new OptionsResolver();
4435

4536
$resolver->setDefaults([
46-
'timeout' => 5,
47-
'verify' => true,
48-
'proxy' => null,
37+
'timeout' => 5,
38+
'verify' => true,
39+
'proxy' => null,
4940
]);
5041

5142
$resolver->setAllowedTypes('timeout', 'int');

Diff for: src/ClientFactory/CurlFactory.php

+4-17
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,12 @@
1313
*/
1414
class CurlFactory implements ClientFactory
1515
{
16-
/**
17-
* @var ResponseFactoryInterface
18-
*/
19-
private $responseFactory;
20-
21-
/**
22-
* @var StreamFactoryInterface
23-
*/
24-
private $streamFactory;
25-
26-
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
27-
{
28-
$this->responseFactory = $responseFactory;
29-
$this->streamFactory = $streamFactory;
16+
public function __construct(
17+
private readonly ResponseFactoryInterface $responseFactory,
18+
private readonly StreamFactoryInterface $streamFactory
19+
) {
3020
}
3121

32-
/**
33-
* {@inheritdoc}
34-
*/
3522
public function createClient(array $config = [])
3623
{
3724
if (!class_exists('Http\Client\Curl\Client')) {

Diff for: src/ClientFactory/Guzzle6Factory.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
*/
1212
class Guzzle6Factory implements ClientFactory
1313
{
14-
/**
15-
* {@inheritdoc}
16-
*/
1714
public function createClient(array $config = [])
1815
{
1916
if (!class_exists('Http\Adapter\Guzzle6\Client')) {

Diff for: src/ClientFactory/Guzzle7Factory.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
*/
1212
class Guzzle7Factory implements ClientFactory
1313
{
14-
/**
15-
* {@inheritdoc}
16-
*/
1714
public function createClient(array $config = [])
1815
{
1916
if (!class_exists('Http\Adapter\Guzzle7\Client')) {

Diff for: src/ClientFactory/MockFactory.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
*/
1313
final class MockFactory implements ClientFactory
1414
{
15-
/**
16-
* @var ClientInterface
17-
*/
18-
private $client;
15+
private ?ClientInterface $client = null;
1916

2017
/**
2118
* Set the client instance that this factory should return.
@@ -27,9 +24,6 @@ public function setClient(ClientInterface $client)
2724
$this->client = $client;
2825
}
2926

30-
/**
31-
* {@inheritdoc}
32-
*/
3327
public function createClient(array $config = [])
3428
{
3529
if (!class_exists(Client::class)) {

Diff for: src/ClientFactory/PluginClientFactory.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
final class PluginClientFactory
2020
{
2121
/**
22-
* @param Plugin[] $plugins
23-
* @param ClientFactory|callable $factory
24-
* @param array $config config to the client factory
25-
* @param array $pluginClientOptions config forwarded to the PluginClient
22+
* @param Plugin[] $plugins
23+
* @param array $config config to the client factory
24+
* @param array $pluginClientOptions config forwarded to the PluginClient
2625
*
2726
* @return PluginClient
2827
*/
29-
public static function createPluginClient(array $plugins, $factory, array $config, array $pluginClientOptions = [])
28+
public static function createPluginClient(array $plugins, ClientFactory|callable $factory, array $config, array $pluginClientOptions = [])
3029
{
3130
if ($factory instanceof ClientFactory) {
3231
$client = $factory->createClient($config);

Diff for: src/ClientFactory/ReactFactory.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
*/
1212
class ReactFactory implements ClientFactory
1313
{
14-
/**
15-
* {@inheritdoc}
16-
*/
1714
public function createClient(array $config = [])
1815
{
1916
if (!class_exists('Http\Adapter\React\Client')) {

Diff for: src/ClientFactory/SocketFactory.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
*/
1212
class SocketFactory implements ClientFactory
1313
{
14-
/**
15-
* {@inheritdoc}
16-
*/
1714
public function createClient(array $config = [])
1815
{
1916
if (!class_exists('Http\Client\Socket\Client')) {

Diff for: src/ClientFactory/SymfonyFactory.php

+4-17
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,12 @@
1414
*/
1515
class SymfonyFactory implements ClientFactory
1616
{
17-
/**
18-
* @var ResponseFactoryInterface
19-
*/
20-
private $responseFactory;
21-
22-
/**
23-
* @var StreamFactoryInterface
24-
*/
25-
private $streamFactory;
26-
27-
public function __construct(ResponseFactoryInterface $responseFactory, StreamFactoryInterface $streamFactory)
28-
{
29-
$this->responseFactory = $responseFactory;
30-
$this->streamFactory = $streamFactory;
17+
public function __construct(
18+
private readonly ResponseFactoryInterface $responseFactory,
19+
private readonly StreamFactoryInterface $streamFactory
20+
) {
3121
}
3222

33-
/**
34-
* {@inheritdoc}
35-
*/
3623
public function createClient(array $config = [])
3724
{
3825
if (!class_exists(HttplugClient::class)) {

0 commit comments

Comments
 (0)