Skip to content

Commit bdcf92e

Browse files
committed
Cleaned up checks
1 parent 0f4d24a commit bdcf92e

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

src/Ip.php

+15-17
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,20 @@ protected static function processWithSlash($range)
251251
protected static function processWithAsterisk($range)
252252
{
253253
if (strpos($range, '*') !== false) {
254-
if (self::$isv6) {
255-
$lower = str_replace('*', '0000', $range);
256-
$upper = str_replace('*', 'ffff', $range);
257-
} else {
258-
$lower = str_replace('*', '0', $range);
259-
$upper = str_replace('*', '255', $range);
260-
}
254+
255+
$lowerRange = self::$isv6 ? '0000' : '0';
256+
$upperRange = self::$isv6 ? 'ffff' : '255';
257+
258+
$lower = str_replace('*',$lowerRange, $range);
259+
$upper = str_replace('*',$upperRange, $range);
260+
261261
$range = $lower . '-' . $upper;
262262
}
263+
263264
if (strpos($range, '-') !== false) {
264265
return self::processWithMinus($range);
265266
}
267+
266268
return false;
267269
}
268270

@@ -353,18 +355,14 @@ public static function long2ip($dec, $ipv6 = false)
353355

354356
public static function matchRange($ip, $range)
355357
{
356-
$ipItems = explode('.', $ip);
357-
$rangeItems = explode('.', $range);
358+
$ipParts = explode('.', $ip);
359+
$rangeParts = explode('.', $range);
358360

359-
$ipItems = array_filter($ipItems, function ($subnet) {
360-
return $subnet !== '';
361-
});
362-
$rangeItems = array_filter($rangeItems, function ($subnet) {
363-
return $subnet !== '';
364-
});
361+
$ipParts = array_filter($ipParts);
362+
$rangeParts = array_filter($rangeParts);
365363

366-
$ipItems = array_slice($ipItems, 0, count($rangeItems));
364+
$ipParts = array_slice($ipParts, 0, count($rangeParts));
367365

368-
return implode('.', $rangeItems) === implode('.', $ipItems);
366+
return implode('.', $rangeParts) === implode('.', $ipParts);
369367
}
370368
}

0 commit comments

Comments
 (0)