Skip to content

Commit a2cb1ca

Browse files
committed
Simplify getPartialIP()
1 parent fd1ecee commit a2cb1ca

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/libraries/Authentication.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,12 @@ protected static function getFingerprint(User &$user) {
101101
*/
102102
protected static function getPartialIP(string $ip) {
103103
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
104-
$r = long2ip(ip2long($ip) & 0xFFFFFF00);
104+
return long2ip(ip2long($ip) & 0xFFFFFF00);
105105
} else if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
106-
$r = inet_ntop(
107-
substr(unpack('A16', inet_pton($ip))[1], 0, 8) . str_repeat(chr(0), 8)
108-
);
106+
return inet_ntop(substr(inet_pton($ip), 0, 8) . str_repeat(chr(0), 8));
109107
} else {
110108
throw new InvalidArgumentException('$ip is not a valid IP address');
111109
}
112-
return $r;
113110
}
114111

115112
/**

0 commit comments

Comments
 (0)