diff --git a/src/IP.php b/src/IP.php index b072c4d..ecc2273 100644 --- a/src/IP.php +++ b/src/IP.php @@ -64,7 +64,7 @@ public static function parse(string $ip): self } if (is_numeric($ip)) { - return self::parseLong($ip); + return self::parseLong((int) $ip); } return new self($ip); @@ -197,7 +197,7 @@ public function toLong(): string $octet = self::IP_V6_OCTETS - 1; foreach (unpack('C*', $this->in_addr) as $char) { $exponent = (string) $octet--; - $long = bcadd($long, bcmul((string) $char, bcpow('256', $exponent))); + $long = bcadd((string) $long, bcmul((string) $char, bcpow('256', $exponent))); } } @@ -255,4 +255,4 @@ public function prev(int $to = 1): self return new self(inet_ntop(pack(...array_merge(['C*'], $unpacked)))); } -} +} \ No newline at end of file diff --git a/src/Range.php b/src/Range.php index f6f4440..85551f8 100644 --- a/src/Range.php +++ b/src/Range.php @@ -141,7 +141,7 @@ public function getNetworks(): array $excluded = $span->exclude($this->lastIP->next()->__toString()); } else { $excluded = array_pop($networks); - $excluded = $excluded->exclude($this->lastIP->next()); + $excluded = $excluded->exclude($this->lastIP->next()->__toString()); } foreach ($excluded as $network) { @@ -214,4 +214,4 @@ public function count(): int { return (int) bcadd(bcsub($this->lastIP->toLong(), $this->firstIP->toLong()), '1'); } -} +} \ No newline at end of file diff --git a/tests/IPTest.php b/tests/IPTest.php index d76cfc9..eab2c0d 100644 --- a/tests/IPTest.php +++ b/tests/IPTest.php @@ -101,7 +101,7 @@ public function testParseBinException(): void */ public function testParseLong(): void { - $ipv4long = '2130706433'; + $ipv4long = 2130706433; $ipv4 = IP::parseLong($ipv4long); $ipv6Long = '340277174624079928635746076935438991360'; @@ -197,8 +197,8 @@ public static function getTestConstructorExceptionData(): array return [ ['256.0.0.1'], ['127.-1.0.1'], - [123.45], - [-123.45], + ['123.45'], + ['-123.45'], ['cake'], ['12345'], ['-12345'], @@ -219,7 +219,7 @@ public static function getToStringData(): array public static function getTestParseData(): array { return [ - [2130706433, '127.0.0.1'], // long + ['2130706433', '127.0.0.1'], // long ['0b01111111000000000000000000000001', '127.0.0.1'], // bin ['0x7f000001', '127.0.0.1'], // hex, ['0x20010000000000008000000000000000', '2001::8000:0:0:0'], // hex @@ -270,4 +270,4 @@ public static function getReversePointerData(): array ['2001:db8::567:89ab', 'b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'], ]; } -} +} \ No newline at end of file