Skip to content

Commit

Permalink
Remove call to undefined function, fix typing
Browse files Browse the repository at this point in the history
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
  • Loading branch information
come-nc committed Aug 1, 2022
1 parent ead97ba commit 00b4506
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions lib/private/Http/IpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* @author Fabien Potencier <fabien@symfony.com>
*/
class IpUtils {
/**
* @var array<string,bool>
*/
private static $checkedIps = [];

/**
Expand All @@ -31,13 +34,7 @@ private function __construct() {
*
* @return bool
*/
public static function checkIp(?string $requestIp, $ips) {
if (null === $requestIp) {
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);

return false;
}

public static function checkIp(string $requestIp, $ips) {
if (!\is_array($ips)) {
$ips = [$ips];
}
Expand All @@ -61,13 +58,7 @@ public static function checkIp(?string $requestIp, $ips) {
*
* @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet
*/
public static function checkIp4(?string $requestIp, string $ip) {
if (null === $requestIp) {
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);

return false;
}

public static function checkIp4(string $requestIp, string $ip) {
$cacheKey = $requestIp.'-'.$ip;
if (isset(self::$checkedIps[$cacheKey])) {
return self::$checkedIps[$cacheKey];
Expand All @@ -81,9 +72,11 @@ public static function checkIp4(?string $requestIp, string $ip) {
[$address, $netmask] = explode('/', $ip, 2);

if ('0' === $netmask) {
return self::$checkedIps[$cacheKey] = filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
return self::$checkedIps[$cacheKey] = (bool)filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
}

$netmask = (int)$netmask;

if ($netmask < 0 || $netmask > 32) {
return self::$checkedIps[$cacheKey] = false;
}
Expand Down Expand Up @@ -113,13 +106,7 @@ public static function checkIp4(?string $requestIp, string $ip) {
*
* @throws \RuntimeException When IPV6 support is not enabled
*/
public static function checkIp6(?string $requestIp, string $ip) {
if (null === $requestIp) {
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);

return false;
}

public static function checkIp6(string $requestIp, string $ip) {
$cacheKey = $requestIp.'-'.$ip;
if (isset(self::$checkedIps[$cacheKey])) {
return self::$checkedIps[$cacheKey];
Expand All @@ -136,6 +123,8 @@ public static function checkIp6(?string $requestIp, string $ip) {
return (bool) unpack('n*', @inet_pton($address));
}

$netmask = (int)$netmask;

if ($netmask < 1 || $netmask > 128) {
return self::$checkedIps[$cacheKey] = false;
}
Expand Down

0 comments on commit 00b4506

Please sign in to comment.