Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHP 8.4 to CI Pipeline #93

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ jobs:
strategy:
matrix:
php:
- '7.4'
- '8.3'
- '8.4'
steps:
- uses: 'actions/checkout@v2'
- uses: 'shivammathur/setup-php@v2'
Expand All @@ -28,5 +30,5 @@ jobs:
# Require PHPStan via command-line instead of adding to Composer's
# "require-dev"; we only want to run static analysis once on the highest
# version of PHP available.
- run: 'composer require --dev phpstan/phpstan phpstan/phpstan-deprecation-rules'
- run: 'composer require --dev "phpstan/phpstan:^2" "phpstan/phpstan-deprecation-rules"'
- run: './vendor/bin/phpstan analyze --no-progress --error-format="github"'
4 changes: 3 additions & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- uses: 'actions/checkout@v2'
- uses: 'shivammathur/setup-php@v2'
with:
php-version: '${{ matrix.php }}'
- run: 'find src/ -type f -name "*.php" -print0 | xargs -0 -n1 -P4 php -l -n | (! grep -v "No syntax errors detected" )'
- 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" )'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't not trigger deprecations in 8.4 without removing support for < 7.1


unit-testing:
runs-on: 'ubuntu-20.04'
Expand All @@ -48,6 +49,7 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- uses: 'actions/checkout@v2'
- uses: 'shivammathur/setup-php@v2'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Full documentation is available in the [`docs/`](docs/) folder.
## Compatibility

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

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

> The Doctrine features for this library have been split off into their own
Expand Down
8 changes: 6 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ parameters:
level: 'max'
paths: [ 'src', 'tests' ]
checkFunctionNameCase: true
checkGenericClassInNonGenericObjectType: true
reportUnmatchedIgnoredErrors: true
treatPhpDocTypesAsCertain: false
parallel:
maximumNumberOfProcesses: 4
ignoreErrors:
-
# This project purposefully uses variable constructors and "new static()".
message: "#^Unsafe usage of new static\\(\\)\\.$#"
identifier: new.static
-
# We cannot fix PHP 8.4 deprecation errors without removing support for PHP versions <7.1
# (but it means this error won't be matched on PHP versoins <8.4)
identifier: parameter.implicitlyNullable
reportUnmatched: false

includes:
- 'vendor/phpstan/phpstan-deprecation-rules/rules.neon'
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/ConsistentFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function ntopVersion4($binary)
// $pack return type is `string|false` below PHP 8 and `string`
// above PHP 8.
$pack = \pack('A4', $binary);
/** @phpstan-ignore-next-line (@phpstan-ignore identical.alwaysFalse) */
// @phpstan-ignore identical.alwaysFalse
if (false === $pack || false === $protocol = \inet_ntop($pack)) {
throw new FormatException($binary);
}
Expand Down
16 changes: 11 additions & 5 deletions src/Formatter/NativeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function ntop($binary)
$pack = \pack(\sprintf('A%d', $length), $binary);
// $pack return type is `string|false` below PHP 8 and `string`
// above PHP 8.
/** @phpstan-ignore-next-line (@phpstan-ignore identical.alwaysFalse) */
// @phpstan-ignore identical.alwaysFalse
if (false === $pack || false === $protocol = \inet_ntop($pack)) {
throw new FormatException($binary);
}
Expand All @@ -36,17 +36,23 @@ public function pton($binary)
if (\is_string($binary)) {
if (\filter_var($binary, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
$number = \inet_pton($binary);
if (false === $number || false === $sequence = \unpack('a4', $number)) {
if (false === $number
|| false === ($sequence = \unpack('a4', $number))
|| !is_string($return = \current($sequence))
) {
throw new FormatException($binary);
}
return \current($sequence);
return $return;
}
if (\filter_var($binary, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
$number = \inet_pton($binary);
if (false === $number || false === $sequence = \unpack('a16', $number)) {
if (false === $number
|| false === ($sequence = \unpack('a16', $number))
|| !is_string($return = \current($sequence))
) {
throw new FormatException($binary);
}
return \current($sequence);
return $return;
}
$length = MbString::getLength($binary);
if ($length === 4 || $length === 16) {
Expand Down
4 changes: 2 additions & 2 deletions src/Util/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static function toHex($binary)
if (!\is_string($binary)) {
throw new \InvalidArgumentException('Cannot convert non-string to hexadecimal.');
}
if (false === $data = \unpack('H*', $binary)) {
if (false === ($data = \unpack('H*', $binary)) || !is_string($hex = \reset($data))) {
throw new \InvalidArgumentException('Unknown error converting string to hexadecimal.');
}
return \reset($data);
return $hex;
}

/**
Expand Down
11 changes: 8 additions & 3 deletions src/Util/MbString.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ public static function getLength($str)
*/
public static function subString($str, $start, $length = null)
{
return \function_exists('\\mb_substr')
? (\mb_substr($str, $start, $length, '8bit') ?: '')
: (\substr($str, $start, $length) ?: '');
if (\function_exists('\\mb_substr')) {
return (\mb_substr($str, $start, $length, '8bit') ?: '');
}
return is_int($length)
? (\substr($str, $start, $length) ?: '')
// On PHP versions 7.2 to 7.4, the $length argument cannot be null.
// The official PHP docs do not mention this peculiarity.
: (\substr($str, $start) ?: '');
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Version/IPv4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value)
$this->expectException(\Darsyn\IP\Exception\InvalidIpAddressException::class);
$this->expectExceptionMessage('The IP address supplied is not valid.');
try {
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
// @phpstan-ignore argument.type
IP::factory($value);
} catch (InvalidIpAddressException $e) {
$this->assertSame($value, $e->getSuppliedIp());
Expand Down Expand Up @@ -197,7 +197,7 @@ public function testCidrMasks($cidr, $expectedMaskHex)
$reflect = new \ReflectionClass($ip);
$method = $reflect->getMethod('generateBinaryMask');
$method->setAccessible(true);
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
// @phpstan-ignore argument.type
$actualMask = unpack('H*hex', $method->invoke($ip, $cidr, 4));
$this->assertSame($expectedMaskHex, is_array($actualMask) ? $actualMask['hex'] : null);
}
Expand All @@ -220,7 +220,7 @@ public function testExceptionIsThrownFromInvalidCidrValues($cidr)
$method->setAccessible(true);
try {
$method->invoke($ip, $cidr, 4);
/** @phpstan-ignore-next-line (@phpstan-ignore catch.neverThrown) */
// @phpstan-ignore catch.neverThrown
} catch (InvalidCidrException $e) {
$this->assertSame($cidr, $e->getSuppliedCidr());
throw $e;
Expand Down Expand Up @@ -288,7 +288,7 @@ public function testInRangeThrowsExceptionOnInvalidCidr($cidr)
$first = IP::factory('12.34.56.78');
$second = IP::factory('12.34.56.78');
$this->expectException(InvalidCidrException::class);
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
// @phpstan-ignore argument.type
$first->inRange($second, $cidr);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/Version/IPv6Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value)
$this->expectException(\Darsyn\IP\Exception\InvalidIpAddressException::class);
$this->expectExceptionMessage('The IP address supplied is not valid.');
try {
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
// @phpstan-ignore argument.type
$ip = IP::factory($value);
} catch (InvalidIpAddressException $e) {
$this->assertSame($value, $e->getSuppliedIp());
Expand Down Expand Up @@ -246,7 +246,7 @@ public function testCidrMasks($cidr, $expectedMaskHex)
$reflect = new \ReflectionClass($ip);
$method = $reflect->getMethod('generateBinaryMask');
$method->setAccessible(true);
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
// @phpstan-ignore argument.type
$actualMask = unpack('H*hex', $method->invoke($ip, $cidr, 16));
$this->assertSame($expectedMaskHex, is_array($actualMask) ? $actualMask['hex'] : null);
}
Expand All @@ -269,7 +269,7 @@ public function testExceptionIsThrownFromInvalidCidrValues($cidr)
$method->setAccessible(true);
try {
$method->invoke($ip, $cidr, 16);
/** @phpstan-ignore-next-line (@phpstan-ignore catch.neverThrown) */
// @phpstan-ignore catch.neverThrown
} catch (InvalidCidrException $e) {
$this->assertSame($cidr, $e->getSuppliedCidr());
throw $e;
Expand Down
2 changes: 1 addition & 1 deletion tests/Version/MultiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value)
$this->expectException(InvalidIpAddressException::class);
$this->expectExceptionMessage('The IP address supplied is not valid.');
try {
/** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */
// @phpstan-ignore argument.type
$ip = IP::factory($value);
} catch (InvalidIpAddressException $e) {
$this->assertSame($value, $e->getSuppliedIp());
Expand Down