Skip to content

Commit cf739a9

Browse files
vjiksamdark
andauthored
Fix incorrect check error while converting IP + Fix psalm (#59)
Co-authored-by: Alexander Makarov <[email protected]>
1 parent 6f8c0fc commit cf739a9

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

.github/workflows/static.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ on:
1010
- 'phpunit.xml.dist'
1111

1212
push:
13+
branches:
14+
- master
1315
paths-ignore:
1416
- 'docs/**'
1517
- 'README.md'
@@ -28,4 +30,4 @@ jobs:
2830
os: >-
2931
['ubuntu-latest']
3032
php: >-
31-
['7.4', '8.0', '8.1']
33+
['7.4', '8.0', '8.1', '8.2', '8.3']

CHANGELOG.md

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

33
## 1.0.2 under development
44

5-
- no changes in this release.
5+
- Bug #59: Fix error while converting IP address to bits representation in PHP 8.0+ (@vjik)
66

77
## 1.0.1 January 27, 2022
88

9-
- Bug #40: Fix return type for callback of `set_error_handler()` function (devanych)
9+
- Bug #40: Fix return type for callback of `set_error_handler()` function (@devanych)
1010

1111
## 1.0.0 March 04, 2021
1212

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"rector/rector": "^1.2",
3838
"roave/infection-static-analysis-plugin": "^1.16",
3939
"spatie/phpunit-watcher": "^1.23",
40-
"vimeo/psalm": "^4.18"
40+
"vimeo/psalm": "^4.30|^5.25"
4141
},
4242
"autoload": {
4343
"psr-4": {

psalm.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?xml version="1.0"?>
22
<psalm
33
errorLevel="1"
4+
findUnusedBaselineEntry="true"
5+
findUnusedCode="false"
46
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
57
xmlns="https://getpsalm.org/schema/config"
68
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"

src/DnsHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public static function existsA(string $hostname): bool
7070
public static function acceptsEmails(string $hostnameOrEmail): bool
7171
{
7272
if (strpos($hostnameOrEmail, '@') !== false) {
73+
/**
74+
* @psalm-suppress PossiblyUndefinedArrayOffset In this case `explode()` always returns an array with 2 elements.
75+
*/
7376
[, $hostnameOrEmail] = explode('@', $hostnameOrEmail, 2);
7477
}
7578
return self::existsMx($hostnameOrEmail) || self::existsA($hostnameOrEmail);

src/IpHelper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ final class IpHelper
5252
* @param string $ip The valid IPv4 or IPv6 address.
5353
* @param bool $validate Enable perform IP address validation. False is best practice if the data comes from a trusted source.
5454
*
55-
* @return int {@see IPV4} or {@see IPV6}.
55+
* @return int Value of either {@see IPV4} or {@see IPV6} constant.
5656
*/
5757
public static function getIpVersion(string $ip, bool $validate = true): int
5858
{
@@ -173,7 +173,7 @@ public static function ip2bin(string $ip): string
173173
$result = '';
174174
for ($i = 0, $iMax = strlen($ipBinary); $i < $iMax; $i += 4) {
175175
$data = substr($ipBinary, $i, 4);
176-
if (!is_string($data)) {
176+
if (empty($data)) {
177177
throw new RuntimeException('An error occurred while converting IP address to bits representation.');
178178
}
179179
/** @psalm-suppress MixedArgument */

0 commit comments

Comments
 (0)