Skip to content

Commit d7c72e3

Browse files
overtrueCopilot
andauthored
Add Symfony 8 compatibility support (#2982)
* Add Symfony 8 compatibility support * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix CI failures on PHP 8 and lint jobs --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 1722508 commit d7c72e3

44 files changed

Lines changed: 205 additions & 115 deletions

Some content is hidden

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

.github/workflows/test.yml

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on: [push, pull_request]
33

44
jobs:
55
phpunit:
6-
name: PHP-${{ matrix.php_version }}-${{ matrix.perfer }}
6+
name: PHP-${{ matrix.php_version }}-${{ matrix.prefer }}
77
runs-on: ubuntu-latest
88
strategy:
99
fail-fast: false
@@ -15,12 +15,39 @@ jobs:
1515
- 8.3
1616
- 8.4
1717
- 8.5
18-
perfer:
18+
prefer:
1919
- stable
2020
- lowest
2121
steps:
22-
- uses: actions/checkout@master
23-
- name: Install Dependencies
24-
run: composer update --prefer-dist --no-interaction --no-suggest --prefer-${{ matrix.perfer }}
25-
- name: Run PHPUnit
26-
run: ./vendor/bin/phpunit
22+
- uses: actions/checkout@v4
23+
- uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: ${{ matrix.php_version }}
26+
coverage: none
27+
- name: Install Dependencies
28+
run: composer update --prefer-dist --no-interaction --prefer-${{ matrix.prefer }}
29+
- name: Run PHPUnit
30+
run: ./vendor/bin/phpunit
31+
32+
phpunit-symfony-8:
33+
name: PHP-8.4-symfony-8
34+
runs-on: ubuntu-latest
35+
steps:
36+
- uses: actions/checkout@v4
37+
- uses: shivammathur/setup-php@v2
38+
with:
39+
php-version: '8.4'
40+
coverage: none
41+
- name: Require Symfony 8
42+
run: |
43+
composer require --no-interaction --no-update \
44+
"symfony/cache:^8.0" \
45+
"symfony/http-foundation:^8.0" \
46+
"symfony/psr-http-message-bridge:^8.0" \
47+
"symfony/http-client:^8.0" \
48+
"symfony/mime:^8.0" \
49+
"symfony/var-dumper:^8.0"
50+
- name: Install Dependencies
51+
run: composer update -W --prefer-dist --no-interaction
52+
- name: Run PHPUnit
53+
run: ./vendor/bin/phpunit

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@
2727
"overtrue/socialite": "^3.5.4|^4.0.1",
2828
"psr/simple-cache": "^1.0|^2.0|^3.0",
2929
"psr/http-client": "^1.0",
30-
"symfony/cache": "^5.4|^6.0|^7.0",
31-
"symfony/http-foundation": "^5.4|^6.0|^7.0",
32-
"symfony/psr-http-message-bridge": "^2.1.2|^6.4.0|^7.1",
33-
"symfony/http-client": "^5.4|^6.0|^7.0",
34-
"symfony/mime": "^5.4|^6.0|^7.0",
30+
"symfony/cache": "^5.4|^6.0|^7.0|^8.0",
31+
"symfony/http-foundation": "^5.4|^6.0|^7.0|^8.0",
32+
"symfony/psr-http-message-bridge": "^2.1.2|^6.4.0|^7.1|^8.0",
33+
"symfony/http-client": "^5.4|^6.0|^7.0|^8.0",
34+
"symfony/mime": "^5.4|^6.0|^7.0|^8.0",
3535
"symfony/polyfill-php81": "^1.25",
3636
"thenorthmemory/xml": "^1.0"
3737
},
@@ -40,7 +40,7 @@
4040
"mockery/mockery": "^1.4.4",
4141
"phpstan/phpstan": "^1.0 | ^2",
4242
"phpunit/phpunit": "^9.5",
43-
"symfony/var-dumper": "^5.2|^6|^7",
43+
"symfony/var-dumper": "^5.2|^6|^7|^8.0",
4444
"jetbrains/phpstorm-attributes": "^1.0",
4545
"laravel/pint": "^1.2"
4646
},

src/Kernel/Config.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use EasyWeChat\Kernel\Contracts\Config as ConfigInterface;
99
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
1010
use EasyWeChat\Kernel\Support\Arr;
11+
use JetBrains\PhpStorm\Pure;
1112

1213
use function strval;
1314

@@ -32,7 +33,7 @@ public function __construct(
3233
$this->checkMissingKeys();
3334
}
3435

35-
#[\JetBrains\PhpStorm\Pure]
36+
#[Pure]
3637
public function has(string $key): bool
3738
{
3839
return Arr::has($this->items, $key);
@@ -41,7 +42,7 @@ public function has(string $key): bool
4142
/**
4243
* @param array<string>|string $key
4344
*/
44-
#[\JetBrains\PhpStorm\Pure]
45+
#[Pure]
4546
public function get(array|string $key, mixed $default = null): mixed
4647
{
4748
if (is_array($key)) {
@@ -55,7 +56,7 @@ public function get(array|string $key, mixed $default = null): mixed
5556
* @param array<string> $keys
5657
* @return array<string, mixed>
5758
*/
58-
#[\JetBrains\PhpStorm\Pure]
59+
#[Pure]
5960
public function getMany(array $keys): array
6061
{
6162
$config = [];
@@ -84,13 +85,13 @@ public function all(): array
8485
return $this->items;
8586
}
8687

87-
#[\JetBrains\PhpStorm\Pure]
88+
#[Pure]
8889
public function offsetExists(mixed $offset): bool
8990
{
9091
return $this->has(strval($offset));
9192
}
9293

93-
#[\JetBrains\PhpStorm\Pure]
94+
#[Pure]
9495
public function offsetGet(mixed $offset): mixed
9596
{
9697
return $this->get(strval($offset));

src/Kernel/Encryptor.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Exception;
1515
use Throwable;
1616

17+
use function array_map;
1718
use function base64_decode;
1819
use function base64_encode;
1920
use function implode;
@@ -131,7 +132,7 @@ public function encryptAsJson(string $plaintext, ?string $nonce = null, int|stri
131132
}
132133

133134
/**
134-
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
135+
* @throws RuntimeException
135136
*/
136137
public function encryptAsArray(string $plaintext, ?string $nonce = null, int|string|null $timestamp = null): array
137138
{
@@ -164,11 +165,16 @@ public function encryptAsArray(string $plaintext, ?string $nonce = null, int|str
164165
];
165166
}
166167

167-
public function createSignature(mixed ...$attributes): string
168+
public function createSignature(string|int ...$attributes): string
168169
{
170+
$attributes = array_map(
171+
static fn (string|int $attribute): string => (string) $attribute,
172+
$attributes
173+
);
174+
169175
sort($attributes, SORT_STRING);
170176

171-
return sha1(implode($attributes));
177+
return sha1(implode('', $attributes));
172178
}
173179

174180
/**

src/Kernel/Form/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class File extends DataPart
1919
{
2020
/**
21-
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
21+
* @throws RuntimeException
2222
*/
2323
public static function from(
2424
string $pathOrContents,

src/Kernel/Form/Form.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace EasyWeChat\Kernel\Form;
44

5+
use JetBrains\PhpStorm\ArrayShape;
56
use Symfony\Component\Mime\Part\DataPart;
67
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
78

@@ -25,7 +26,7 @@ public static function create(array $fields): Form
2526
/**
2627
* @return array{headers:array<string,string|string[]>,body:string}
2728
*/
28-
#[\JetBrains\PhpStorm\ArrayShape(['headers' => 'array', 'body' => 'string'])]
29+
#[ArrayShape(['headers' => 'array', 'body' => 'string'])]
2930
public function toArray(): array
3031
{
3132
return $this->toOptions();
@@ -34,7 +35,7 @@ public function toArray(): array
3435
/**
3536
* @return array{headers:array<string,string|string[]>,body:string}
3637
*/
37-
#[\JetBrains\PhpStorm\ArrayShape(['headers' => 'array', 'body' => 'string'])]
38+
#[ArrayShape(['headers' => 'array', 'body' => 'string'])]
3839
public function toOptions(): array
3940
{
4041
$formData = new FormDataPart($this->fields);

src/Kernel/HttpClient/RequestUtil.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use EasyWeChat\Kernel\Support\UserAgent;
1010
use EasyWeChat\Kernel\Support\Xml;
1111
use InvalidArgumentException;
12+
use JetBrains\PhpStorm\ArrayShape;
1213
use Nyholm\Psr7\Factory\Psr17Factory;
1314
use Nyholm\Psr7Server\ServerRequestCreator;
1415
use Psr\Http\Message\ServerRequestInterface;
@@ -27,7 +28,7 @@ class RequestUtil
2728
* @param array<string, mixed> $options
2829
* @return array<string, mixed>
2930
*/
30-
#[\JetBrains\PhpStorm\ArrayShape([
31+
#[ArrayShape([
3132
'status_codes' => 'array',
3233
'delay' => 'int',
3334
'max_delay' => 'int',

src/Kernel/HttpClient/Response.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
use function strtolower;
3333

3434
/**
35-
* @implements \ArrayAccess<array-key, mixed>
35+
* @implements ArrayAccess<array-key, mixed>
3636
*
37-
* @see \Symfony\Contracts\HttpClient\ResponseInterface
37+
* @see ResponseInterface
3838
*/
3939
class Response implements Arrayable, ArrayAccess, Jsonable, ResponseInterface, StreamableInterface
4040
{
@@ -269,15 +269,19 @@ public function hasHeader(string $name, ?bool $throw = null): bool
269269
return isset($this->getHeaders($throw)[$name]);
270270
}
271271

272-
/**
273-
* @return array<array-key, mixed>
274-
*/
275272
public function getHeader(string $name, ?bool $throw = null): array
276273
{
277274
$name = strtolower($name);
278275
$throw ??= $this->throw;
279276

280-
return $this->hasHeader($name, $throw) ? $this->getHeaders($throw)[$name] : [];
277+
if (! $this->hasHeader($name, $throw)) {
278+
return [];
279+
}
280+
281+
/** @var array<string> $headers */
282+
$headers = $this->getHeaders($throw)[$name];
283+
284+
return $headers;
281285
}
282286

283287
public function getHeaderLine(string $name, ?bool $throw = null): string

src/Kernel/Support/Arr.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
namespace EasyWeChat\Kernel\Support;
66

7+
use JetBrains\PhpStorm\Pure;
8+
79
use function is_string;
810

911
class Arr
1012
{
11-
#[\JetBrains\PhpStorm\Pure]
13+
#[Pure]
1214
public static function get(mixed $array, string|int|null $key, mixed $default = null): mixed
1315
{
1416
if (! is_array($array)) {
@@ -95,7 +97,7 @@ public static function dot(array $array, string $prepend = ''): array
9597
* @param array<string|int, mixed> $array
9698
* @param string|int|array<string|int, mixed>|null $keys
9799
*/
98-
#[\JetBrains\PhpStorm\Pure]
100+
#[Pure]
99101
public static function has(array $array, string|int|array|null $keys): bool
100102
{
101103
if (is_null($keys)) {

src/Kernel/Support/PrivateKey.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace EasyWeChat\Kernel\Support;
44

5+
use JetBrains\PhpStorm\Pure;
6+
57
use function file_exists;
68
use function file_get_contents;
79
use function str_starts_with;
@@ -29,7 +31,7 @@ public function getPassphrase(): ?string
2931
return $this->passphrase;
3032
}
3133

32-
#[\JetBrains\PhpStorm\Pure]
34+
#[Pure]
3335
public function __toString(): string
3436
{
3537
return $this->getKey();

0 commit comments

Comments
 (0)