Skip to content

Commit c45e9c2

Browse files
committed
feat: Require PHP >= 8.2
1 parent f483081 commit c45e9c2

39 files changed

Lines changed: 192 additions & 115 deletions

.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: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ 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

.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

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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use MessagePack\Extension;
1616
use MessagePack\Packer;
1717

18-
class DateTimeExtension implements Extension
18+
final class DateTimeExtension implements Extension
1919
{
2020
private $type;
2121

@@ -24,11 +24,16 @@ public function __construct(int $type)
2424
$this->type = $type;
2525
}
2626

27+
#[\Override]
2728
public function getType() : int
2829
{
2930
return $this->type;
3031
}
3132

33+
/**
34+
* @param mixed $value
35+
*/
36+
#[\Override]
3237
public function pack(Packer $packer, $value) : ?string
3338
{
3439
if (!$value instanceof \DateTimeInterface) {
@@ -38,6 +43,10 @@ public function pack(Packer $packer, $value) : ?string
3843
return $packer->packExt($this->type, $value->format('YmdHisue'));
3944
}
4045

46+
/**
47+
* @return \DateTimeImmutable|false
48+
*/
49+
#[\Override]
4150
public function unpackExt(BufferUnpacker $unpacker, int $extLength)
4251
{
4352
return \DateTimeImmutable::createFromFormat('YmdHisue', $unpacker->read($extLength));

examples/MessagePack/StructListExtension.php

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

18-
class StructListExtension implements Extension
18+
final class StructListExtension implements Extension
1919
{
2020
private $type;
2121

@@ -24,11 +24,16 @@ public function __construct(int $type)
2424
$this->type = $type;
2525
}
2626

27+
#[\Override]
2728
public function getType() : int
2829
{
2930
return $this->type;
3031
}
3132

33+
/**
34+
* @param mixed $value
35+
*/
36+
#[\Override]
3237
public function pack(Packer $packer, $value) : ?string
3338
{
3439
if (!$value instanceof StructList) {
@@ -40,7 +45,12 @@ public function pack(Packer $packer, $value) : ?string
4045
return $packer->packArray($value->list);
4146
}
4247

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

4555
$values = '';
4656
foreach ($value->list as $item) {
@@ -56,6 +66,10 @@ public function pack(Packer $packer, $value) : ?string
5666
);
5767
}
5868

69+
/**
70+
* @return array<int, array<array-key, mixed>>
71+
*/
72+
#[\Override]
5973
public function unpackExt(BufferUnpacker $unpacker, int $extLength)
6074
{
6175
$keys = $unpacker->unpackArray();

examples/MessagePack/TextExtension.php

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

18-
class TextExtension implements Extension
18+
final class TextExtension implements Extension
1919
{
2020
private $type;
2121
private $minLength;
@@ -26,11 +26,16 @@ public function __construct(int $type, int $minLength = 100)
2626
$this->minLength = $minLength;
2727
}
2828

29+
#[\Override]
2930
public function getType() : int
3031
{
3132
return $this->type;
3233
}
3334

35+
/**
36+
* @param mixed $value
37+
*/
38+
#[\Override]
3439
public function pack(Packer $packer, $value) : ?string
3540
{
3641
if (!$value instanceof Text) {
@@ -43,18 +48,31 @@ public function pack(Packer $packer, $value) : ?string
4348
}
4449

4550
$context = \deflate_init(\ZLIB_ENCODING_GZIP);
51+
if (false === $context) {
52+
return $packer->packStr($value->str);
53+
}
54+
4655
$compressed = \deflate_add($context, $value->str, \ZLIB_FINISH);
56+
if (false === $compressed) {
57+
return $packer->packStr($value->str);
58+
}
4759

4860
return isset($compressed[$length - 1])
4961
? $packer->packStr($value->str)
5062
: $packer->packExt($this->type, $compressed);
5163
}
5264

65+
/**
66+
* @return string|false
67+
*/
68+
#[\Override]
5369
public function unpackExt(BufferUnpacker $unpacker, int $extLength)
5470
{
5571
$compressed = $unpacker->read($extLength);
5672
$context = \inflate_init(\ZLIB_ENCODING_GZIP);
5773

58-
return \inflate_add($context, $compressed, \ZLIB_FINISH);
74+
return false === $context
75+
? false
76+
: \inflate_add($context, $compressed, \ZLIB_FINISH);
5977
}
6078
}

examples/MessagePack/TraversableExtension.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use MessagePack\Extension;
1616
use MessagePack\Packer;
1717

18-
class TraversableExtension implements Extension
18+
final class TraversableExtension implements Extension
1919
{
2020
private $type;
2121

@@ -24,11 +24,16 @@ public function __construct(int $type)
2424
$this->type = $type;
2525
}
2626

27+
#[\Override]
2728
public function getType() : int
2829
{
2930
return $this->type;
3031
}
3132

33+
/**
34+
* @param mixed $value
35+
*/
36+
#[\Override]
3237
public function pack(Packer $packer, $value) : ?string
3338
{
3439
if (!$value instanceof \Traversable) {
@@ -47,6 +52,10 @@ public function pack(Packer $packer, $value) : ?string
4752
);
4853
}
4954

55+
/**
56+
* @return \Generator
57+
*/
58+
#[\Override]
5059
public function unpackExt(BufferUnpacker $unpacker, int $extLength)
5160
{
5261
$size = $unpacker->unpackArrayHeader();

examples/MessagePack/Uint64.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function __toString() : string
2929
return $this->value;
3030
}
3131

32+
#[\Override]
3233
public function pack(Packer $packer) : string
3334
{
3435
return "\xcf".\gmp_export($this->value);

0 commit comments

Comments
 (0)