Skip to content

Commit 17fdc1e

Browse files
authored
feat: Require PHP >= 8.2 (#41)
1 parent f483081 commit 17fdc1e

44 files changed

Lines changed: 234 additions & 188 deletions

Some content is hidden

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

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ examples export-ignore
33
tests export-ignore
44
.gitattributes export-ignore
55
.gitignore export-ignore
6-
.php_cs.dist export-ignore
6+
.php-cs-fixer.dist.php export-ignore
77
dockerfile.sh export-ignore
88
phpunit.xml.dist export-ignore
99
psalm.xml export-ignore

.github/workflows/qa.yml

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,17 @@ jobs:
1111
matrix:
1212
operating-system: [ubuntu-latest]
1313
env:
14-
- PHP_IMAGE: php:7.3-cli
15-
16-
- PHP_IMAGE: php:7.4-cli
17-
COVERAGE_FILE: coverage.clover
18-
19-
- PHP_IMAGE: php:8.0-cli
20-
QA: 1
21-
22-
- PHP_IMAGE: php:8.1-cli
2314
- PHP_IMAGE: php:8.2-cli
15+
COVERAGE_FILE: coverage.clover
2416
- PHP_IMAGE: php:8.3-cli
17+
QA: 1
2518
- PHP_IMAGE: php:8.4-cli
2619
- PHP_IMAGE: php:8.5-cli
2720

2821
runs-on: ${{ matrix.operating-system }}
2922
steps:
3023
- name: Checkout
31-
uses: actions/checkout@v2
24+
uses: actions/checkout@v6
3225

3326
- name: Build docker image
3427
env: ${{ matrix.env }}

.php_cs.dist renamed to .php-cs-fixer.dist.php

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,35 @@
33
namespace MessagePack;
44

55
use PhpCsFixer\Config;
6+
use PhpCsFixer\Fixer\ConfigurableFixerInterface;
67
use PhpCsFixer\Fixer\ConstantNotation\NativeConstantInvocationFixer;
7-
use PhpCsFixer\Fixer\FixerInterface;
88
use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer;
9+
use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
10+
use PhpCsFixer\FixerDefinition\FixerDefinition;
11+
use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
912
use PhpCsFixer\Tokenizer\Tokens;
1013

11-
final class FilterableFixer implements FixerInterface
14+
final class FilterableFixer implements ConfigurableFixerInterface
1215
{
13-
private $fixer;
14-
private $pathRegex;
16+
private ConfigurableFixerInterface $fixer;
17+
private string $pathRegex;
1518

16-
public function __construct(FixerInterface $fixer, string $pathRegex)
19+
public function __construct(ConfigurableFixerInterface $fixer, string $pathRegex)
1720
{
1821
$this->fixer = $fixer;
1922
$this->pathRegex = $pathRegex;
2023
}
2124

25+
public function configure(array $configuration): void
26+
{
27+
$this->fixer->configure($configuration);
28+
}
29+
30+
public function getConfigurationDefinition(): FixerConfigurationResolver
31+
{
32+
return $this->fixer->getConfigurationDefinition();
33+
}
34+
2235
public function isCandidate(Tokens $tokens) : bool
2336
{
2437
return $this->fixer->isCandidate($tokens);
@@ -52,7 +65,12 @@ public function supports(\SplFileInfo $file) : bool
5265

5366
return $this->fixer->supports($file);
5467
}
55-
};
68+
69+
public function getDefinition() : FixerDefinitionInterface
70+
{
71+
return $this->fixer->getDefinition();
72+
}
73+
}
5674

5775
$header = <<<EOF
5876
This file is part of the rybakit/msgpack.php package.
@@ -63,7 +81,7 @@ public function supports(\SplFileInfo $file) : bool
6381
file that was distributed with this source code.
6482
EOF;
6583

66-
return Config::create()
84+
return (new Config())
6785
->setUsingCache(false)
6886
->setRiskyAllowed(true)
6987
->registerCustomFixers([
@@ -75,13 +93,17 @@ public function supports(\SplFileInfo $file) : bool
7593
'@Symfony:risky' => true,
7694
'array_syntax' => ['syntax' => 'short'],
7795
'binary_operator_spaces' => ['operators' => ['=' => null, '=>' => null]],
78-
'is_null' => false, // https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4015
96+
'fully_qualified_strict_types' => false,
97+
'integer_literal_case' => false,
98+
'is_null' => false,
7999
'native_constant_invocation' => false,
80100
'native_function_invocation' => false,
81-
'FilterableFixer/native_constant_invocation' => true,
82-
'FilterableFixer/native_function_invocation' => true,
101+
'FilterableFixer/native_constant_invocation' => ['strict' => false],
102+
'FilterableFixer/native_function_invocation' => ['strict' => false],
83103
'no_useless_else' => true,
84104
'no_useless_return' => true,
105+
'no_useless_concat_operator' => false,
106+
'no_superfluous_phpdoc_tags' => false,
85107
'ordered_imports' => [
86108
'sort_algorithm' => 'alpha',
87109
'imports_order' => ['class', 'function', 'const'],
@@ -90,6 +112,7 @@ public function supports(\SplFileInfo $file) : bool
90112
'phpdoc_order' => true,
91113
'phpdoc_to_comment' => false,
92114
'return_type_declaration' => ['space_before' => 'one'],
115+
'statement_indentation' => false,
93116
'strict_comparison' => true,
94117
'header_comment' => [
95118
'comment_type' => 'PHPDoc',

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015-2025 Eugene Leonovich
3+
Copyright (c) 2015-2026 Eugene Leonovich
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ composer require rybakit/msgpack
5151

5252
### Packing
5353

54-
To pack values you can either use an instance of a `Packer`:
54+
To pack values, you can either use an instance of a `Packer`:
5555

5656
```php
5757
$packer = new Packer();
@@ -66,8 +66,8 @@ $packed = MessagePack::pack($value);
6666

6767
In the examples above, the method `pack` automatically packs a value depending on its type. However, not all PHP types
6868
can be uniquely translated to MessagePack types. For example, the MessagePack format defines `map` and `array` types,
69-
which are represented by a single `array` type in PHP. By default, the packer will pack a PHP array as a MessagePack
70-
array if it has sequential numeric keys, starting from `0` and as a MessagePack map otherwise:
69+
which are represented by a single `array` type in PHP. By default, the packer will pack a PHP array as a MessagePack
70+
array if it has sequential numeric keys starting from `0`, and as a MessagePack map otherwise:
7171

7272
```php
7373
$mpArr1 = $packer->pack([1, 2]); // MP array [1, 2]
@@ -144,7 +144,7 @@ $packer = new Packer(PackOptions::FORCE_FLOAT32 | PackOptions::FORCE_FLOAT64);
144144

145145
### Unpacking
146146

147-
To unpack data you can either use an instance of a `BufferUnpacker`:
147+
To unpack data, you can either use an instance of a `BufferUnpacker`:
148148

149149
```php
150150
$unpacker = new BufferUnpacker();
@@ -159,8 +159,8 @@ or call a static method on the `MessagePack` class:
159159
$value = MessagePack::unpack($packed);
160160
```
161161

162-
If the packed data is received in chunks (e.g. when reading from a stream), use the `tryUnpack` method, which attempts
163-
to unpack data and returns an array of unpacked messages (if any) instead of throwing an `InsufficientDataException`:
162+
If the packed data is received in chunks (e.g. when reading from a stream), use the `tryUnpack` method, which attempts
163+
to unpack the data and returns an array of unpacked messages (if any) instead of throwing an `InsufficientDataException`:
164164

165165
```php
166166
while ($chunk = ...) {
@@ -286,8 +286,8 @@ $packedArray = $packer->pack([1, 2, 3]);
286286

287287
As with type objects, type transformers are only responsible for *serializing* values. They should be
288288
used when you need to serialize a value that does not implement the [CanBePacked](src/CanBePacked.php)
289-
interface. Examples of such values could be instances of built-in or third-party classes that you don't
290-
own, or non-objects such as resources.
289+
interface. Examples of such values include instances of built-in or third-party classes that you do not
290+
own, or non-objects such as resources.
291291

292292
A transformer class must implement the [CanPack](src/CanPack.php) interface. To use a transformer,
293293
it must first be registered in the packer. Here is an example of how to serialize PHP streams into
@@ -346,7 +346,7 @@ $timestamp = MessagePack::unpack($packedTimestamp);
346346

347347
In addition, the format can be extended with your own types. For example, to make the built-in PHP `DateTime` objects
348348
first-class citizens in your code, you can create a corresponding extension, as shown in the [example](examples/MessagePack/DateTimeExtension.php).
349-
Please note, that custom extensions have to be registered with a unique extension ID (an integer from `0` to `127`).
349+
Please note that custom extensions must be registered with a unique extension ID (an integer from `0` to `127`).
350350

351351
> *More extension examples can be found in the [examples/MessagePack](examples/MessagePack) directory.*
352352
@@ -371,7 +371,7 @@ Run tests as follows:
371371
vendor/bin/phpunit
372372
```
373373

374-
Also, if you already have Docker installed, you can run the tests in a docker container. First, create a container:
374+
Also, if you already have Docker installed, you can run the tests in a Docker container. First, create a container:
375375

376376
```sh
377377
./dockerfile.sh | docker build -t msgpack -
@@ -396,7 +396,7 @@ docker run --rm -v $PWD:/msgpack -w /msgpack msgpack
396396
#### Fuzzing
397397

398398
To ensure that the unpacking works correctly with malformed/semi-malformed data, you can use a testing technique
399-
called [Fuzzing](https://en.wikipedia.org/wiki/Fuzzing). The library ships with a help file (target)
399+
called [fuzzing](https://en.wikipedia.org/wiki/Fuzzing). The library ships with a helper file (target)
400400
for [PHP-Fuzzer](https://github.com/nikic/PHP-Fuzzer) and can be used as follows:
401401

402402
```sh

composer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
}
1212
],
1313
"require": {
14-
"php": "^7.1.1|^8"
14+
"php": "^8.2"
1515
},
1616
"require-dev": {
17+
"ext-decimal": "*",
1718
"ext-gmp": "*",
18-
"friendsofphp/php-cs-fixer": "^2.14",
19-
"phpunit/phpunit": "^7.1|^8|^9",
20-
"vimeo/psalm": "^3.9|^4"
19+
"friendsofphp/php-cs-fixer": "^3",
20+
"phpunit/phpunit": "^11",
21+
"vimeo/psalm": "^5 || ^6"
2122
},
2223
"suggest": {
2324
"ext-decimal": "For converting overflowed integers to Decimal objects",

examples/MessagePack/DateTimeExtension.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
use MessagePack\Extension;
1616
use MessagePack\Packer;
1717

18-
class DateTimeExtension implements Extension
18+
final class DateTimeExtension implements Extension
1919
{
20-
private $type;
21-
22-
public function __construct(int $type)
23-
{
24-
$this->type = $type;
20+
public function __construct(
21+
private readonly int $type,
22+
) {
2523
}
2624

25+
#[\Override]
2726
public function getType() : int
2827
{
2928
return $this->type;
3029
}
3130

31+
/**
32+
* @param mixed $value
33+
*/
34+
#[\Override]
3235
public function pack(Packer $packer, $value) : ?string
3336
{
3437
if (!$value instanceof \DateTimeInterface) {
@@ -38,6 +41,10 @@ public function pack(Packer $packer, $value) : ?string
3841
return $packer->packExt($this->type, $value->format('YmdHisue'));
3942
}
4043

44+
/**
45+
* @return \DateTimeImmutable|false
46+
*/
47+
#[\Override]
4148
public function unpackExt(BufferUnpacker $unpacker, int $extLength)
4249
{
4350
return \DateTimeImmutable::createFromFormat('YmdHisue', $unpacker->read($extLength));

examples/MessagePack/StructList.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313

1414
final class StructList
1515
{
16-
/** @readonly */
17-
public $list;
18-
19-
public function __construct(array $list)
20-
{
21-
$this->list = $list;
16+
public function __construct(
17+
public array $list,
18+
) {
2219
}
2320
}

examples/MessagePack/StructListExtension.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,23 @@
1515
use MessagePack\Extension;
1616
use MessagePack\Packer;
1717

18-
class StructListExtension implements Extension
18+
final class StructListExtension implements Extension
1919
{
20-
private $type;
21-
22-
public function __construct(int $type)
23-
{
24-
$this->type = $type;
20+
public function __construct(
21+
private readonly int $type,
22+
) {
2523
}
2624

25+
#[\Override]
2726
public function getType() : int
2827
{
2928
return $this->type;
3029
}
3130

31+
/**
32+
* @param mixed $value
33+
*/
34+
#[\Override]
3235
public function pack(Packer $packer, $value) : ?string
3336
{
3437
if (!$value instanceof StructList) {
@@ -40,7 +43,12 @@ public function pack(Packer $packer, $value) : ?string
4043
return $packer->packArray($value->list);
4144
}
4245

43-
$keys = \array_keys(\reset($value->list));
46+
$first = \reset($value->list);
47+
if (false === $first) {
48+
return $packer->packArray($value->list);
49+
}
50+
51+
$keys = \array_keys($first);
4452

4553
$values = '';
4654
foreach ($value->list as $item) {
@@ -56,6 +64,10 @@ public function pack(Packer $packer, $value) : ?string
5664
);
5765
}
5866

67+
/**
68+
* @return array<int, array<array-key, mixed>>
69+
*/
70+
#[\Override]
5971
public function unpackExt(BufferUnpacker $unpacker, int $extLength)
6072
{
6173
$keys = $unpacker->unpackArray();

examples/MessagePack/Text.php

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

1414
final class Text
1515
{
16-
/** @readonly */
17-
public $str;
18-
19-
public function __construct(string $str)
20-
{
21-
$this->str = $str;
16+
public function __construct(
17+
public readonly string $str,
18+
) {
2219
}
2320

24-
public function __toString()
21+
public function __toString() : string
2522
{
2623
return $this->str;
2724
}

0 commit comments

Comments
 (0)