Skip to content

Commit ca44e1f

Browse files
committed
ci: 🤖 add PHP 8.4
1 parent bac07f5 commit ca44e1f

File tree

11 files changed

+44
-25
lines changed

11 files changed

+44
-25
lines changed

.github/workflows/static-analysis.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ jobs:
1616
strategy:
1717
matrix:
1818
php:
19+
- '7.4'
1920
- '8.3'
21+
- '8.4'
2022
steps:
2123
- uses: 'actions/checkout@v2'
2224
- uses: 'shivammathur/setup-php@v2'
@@ -28,5 +30,5 @@ jobs:
2830
# Require PHPStan via command-line instead of adding to Composer's
2931
# "require-dev"; we only want to run static analysis once on the highest
3032
# version of PHP available.
31-
- run: 'composer require --dev phpstan/phpstan phpstan/phpstan-deprecation-rules'
33+
- run: 'composer require --dev "phpstan/phpstan:^2" "phpstan/phpstan-deprecation-rules"'
3234
- run: './vendor/bin/phpstan analyze --no-progress --error-format="github"'

.github/workflows/testing.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ jobs:
2626
- '8.1'
2727
- '8.2'
2828
- '8.3'
29+
- '8.4'
2930
steps:
3031
- uses: 'actions/checkout@v2'
3132
- uses: 'shivammathur/setup-php@v2'
3233
with:
3334
php-version: '${{ matrix.php }}'
34-
- run: 'find src/ -type f -name "*.php" -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )'
35+
- run: 'find src/ -type f -name "*.php" -print0 | xargs -0 -n1 -P4 php -d"error_reporting=E_ALL&~E_DEPRECATED" -l -n | (! grep -v "No syntax errors detected" )'
3536

3637
unit-testing:
3738
runs-on: 'ubuntu-20.04'
@@ -48,6 +49,7 @@ jobs:
4849
- '8.1'
4950
- '8.2'
5051
- '8.3'
52+
- '8.4'
5153
steps:
5254
- uses: 'actions/checkout@v2'
5355
- uses: 'shivammathur/setup-php@v2'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Full documentation is available in the [`docs/`](docs/) folder.
1313
## Compatibility
1414

1515
This library has extensive test coverage using PHPUnit on PHP versions: `5.6`,
16-
`7.0`, `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1`, `8.2`, and `8.3`.
16+
`7.0`, `7.1`, `7.2`, `7.3`, `7.4`, `8.0`, `8.1`, `8.2`, `8.3` and `8.4`.
1717

18-
Static analysis is performed with PHPStan at `max` level on PHP `8.3`, using
18+
Static analysis is performed with PHPStan at `max` level on PHP `8.4`, using
1919
core, bleeding edge, and deprecation rules.
2020

2121
> The Doctrine features for this library have been split off into their own

phpstan.neon

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ parameters:
22
level: 'max'
33
paths: [ 'src', 'tests' ]
44
checkFunctionNameCase: true
5-
checkGenericClassInNonGenericObjectType: true
65
reportUnmatchedIgnoredErrors: true
76
treatPhpDocTypesAsCertain: false
87
parallel:
98
maximumNumberOfProcesses: 4
109
ignoreErrors:
1110
-
1211
# This project purposefully uses variable constructors and "new static()".
13-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
12+
identifier: new.static
13+
-
14+
# We cannot fix PHP 8.4 deprecation errors without removing support for PHP versions <7.1
15+
# (but it means this error won't be matched on PHP versoins <8.4)
16+
identifier: parameter.implicitlyNullable
17+
reportUnmatched: false
1418

1519
includes:
1620
- 'vendor/phpstan/phpstan-deprecation-rules/rules.neon'

src/Formatter/ConsistentFormatter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function ntopVersion4($binary)
7373
// $pack return type is `string|false` below PHP 8 and `string`
7474
// above PHP 8.
7575
$pack = \pack('A4', $binary);
76-
/** @phpstan-ignore-next-line (@phpstan-ignore identical.alwaysFalse) */
76+
// @phpstan-ignore identical.alwaysFalse
7777
if (false === $pack || false === $protocol = \inet_ntop($pack)) {
7878
throw new FormatException($binary);
7979
}

src/Formatter/NativeFormatter.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function ntop($binary)
1818
$pack = \pack(\sprintf('A%d', $length), $binary);
1919
// $pack return type is `string|false` below PHP 8 and `string`
2020
// above PHP 8.
21-
/** @phpstan-ignore-next-line (@phpstan-ignore identical.alwaysFalse) */
21+
// @phpstan-ignore identical.alwaysFalse
2222
if (false === $pack || false === $protocol = \inet_ntop($pack)) {
2323
throw new FormatException($binary);
2424
}
@@ -36,17 +36,23 @@ public function pton($binary)
3636
if (\is_string($binary)) {
3737
if (\filter_var($binary, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
3838
$number = \inet_pton($binary);
39-
if (false === $number || false === $sequence = \unpack('a4', $number)) {
39+
if (false === $number
40+
|| false === ($sequence = \unpack('a4', $number))
41+
|| !is_string($return = \current($sequence))
42+
) {
4043
throw new FormatException($binary);
4144
}
42-
return \current($sequence);
45+
return $return;
4346
}
4447
if (\filter_var($binary, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
4548
$number = \inet_pton($binary);
46-
if (false === $number || false === $sequence = \unpack('a16', $number)) {
49+
if (false === $number
50+
|| false === ($sequence = \unpack('a16', $number))
51+
|| !is_string($return = \current($sequence))
52+
) {
4753
throw new FormatException($binary);
4854
}
49-
return \current($sequence);
55+
return $return;
5056
}
5157
$length = MbString::getLength($binary);
5258
if ($length === 4 || $length === 16) {

src/Util/Binary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public static function toHex($binary)
2727
if (!\is_string($binary)) {
2828
throw new \InvalidArgumentException('Cannot convert non-string to hexadecimal.');
2929
}
30-
if (false === $data = \unpack('H*', $binary)) {
30+
if (false === ($data = \unpack('H*', $binary)) || !is_string($hex = \reset($data))) {
3131
throw new \InvalidArgumentException('Unknown error converting string to hexadecimal.');
3232
}
33-
return \reset($data);
33+
return $hex;
3434
}
3535

3636
/**

src/Util/MbString.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ public static function getLength($str)
2323
*/
2424
public static function subString($str, $start, $length = null)
2525
{
26-
return \function_exists('\\mb_substr')
27-
? (\mb_substr($str, $start, $length, '8bit') ?: '')
28-
: (\substr($str, $start, $length) ?: '');
26+
if (\function_exists('\\mb_substr')) {
27+
return (\mb_substr($str, $start, $length, '8bit') ?: '');
28+
}
29+
return is_int($length)
30+
? (\substr($str, $start, $length) ?: '')
31+
// On PHP versions 7.2 to 7.4, the $length argument cannot be null.
32+
// The official PHP docs do not mention this peculiarity.
33+
: (\substr($str, $start) ?: '');
2934
}
3035

3136
/**

tests/Version/IPv4Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value)
7373
$this->expectException(\Darsyn\IP\Exception\InvalidIpAddressException::class);
7474
$this->expectExceptionMessage('The IP address supplied is not valid.');
7575
try {
76-
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
76+
// @phpstan-ignore argument.type
7777
IP::factory($value);
7878
} catch (InvalidIpAddressException $e) {
7979
$this->assertSame($value, $e->getSuppliedIp());
@@ -197,7 +197,7 @@ public function testCidrMasks($cidr, $expectedMaskHex)
197197
$reflect = new \ReflectionClass($ip);
198198
$method = $reflect->getMethod('generateBinaryMask');
199199
$method->setAccessible(true);
200-
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
200+
// @phpstan-ignore argument.type
201201
$actualMask = unpack('H*hex', $method->invoke($ip, $cidr, 4));
202202
$this->assertSame($expectedMaskHex, is_array($actualMask) ? $actualMask['hex'] : null);
203203
}
@@ -220,7 +220,7 @@ public function testExceptionIsThrownFromInvalidCidrValues($cidr)
220220
$method->setAccessible(true);
221221
try {
222222
$method->invoke($ip, $cidr, 4);
223-
/** @phpstan-ignore-next-line (@phpstan-ignore catch.neverThrown) */
223+
// @phpstan-ignore catch.neverThrown
224224
} catch (InvalidCidrException $e) {
225225
$this->assertSame($cidr, $e->getSuppliedCidr());
226226
throw $e;
@@ -288,7 +288,7 @@ public function testInRangeThrowsExceptionOnInvalidCidr($cidr)
288288
$first = IP::factory('12.34.56.78');
289289
$second = IP::factory('12.34.56.78');
290290
$this->expectException(InvalidCidrException::class);
291-
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
291+
// @phpstan-ignore argument.type
292292
$first->inRange($second, $cidr);
293293
}
294294

tests/Version/IPv6Test.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value)
7676
$this->expectException(\Darsyn\IP\Exception\InvalidIpAddressException::class);
7777
$this->expectExceptionMessage('The IP address supplied is not valid.');
7878
try {
79-
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
79+
// @phpstan-ignore argument.type
8080
$ip = IP::factory($value);
8181
} catch (InvalidIpAddressException $e) {
8282
$this->assertSame($value, $e->getSuppliedIp());
@@ -246,7 +246,7 @@ public function testCidrMasks($cidr, $expectedMaskHex)
246246
$reflect = new \ReflectionClass($ip);
247247
$method = $reflect->getMethod('generateBinaryMask');
248248
$method->setAccessible(true);
249-
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
249+
// @phpstan-ignore argument.type
250250
$actualMask = unpack('H*hex', $method->invoke($ip, $cidr, 16));
251251
$this->assertSame($expectedMaskHex, is_array($actualMask) ? $actualMask['hex'] : null);
252252
}
@@ -269,7 +269,7 @@ public function testExceptionIsThrownFromInvalidCidrValues($cidr)
269269
$method->setAccessible(true);
270270
try {
271271
$method->invoke($ip, $cidr, 16);
272-
/** @phpstan-ignore-next-line (@phpstan-ignore catch.neverThrown) */
272+
// @phpstan-ignore catch.neverThrown
273273
} catch (InvalidCidrException $e) {
274274
$this->assertSame($cidr, $e->getSuppliedCidr());
275275
throw $e;

0 commit comments

Comments
 (0)