Skip to content

Commit

Permalink
Refactored due to problem with PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
jamielsharief committed Jan 4, 2021
1 parent ed56e00 commit a88d5b6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/Validation.php
Expand Up @@ -140,7 +140,7 @@ public static function creditCard($value, string $type = 'any'): bool
return false;
}

$value = str_replace([' ', '-'], '', $value);
$value = str_replace([' ', '-'], '', (string) $value);

// 06.12.2019 - Decided to write the regex rules from scratch since
// the public domain ones seem to be outdated.
Expand Down Expand Up @@ -503,10 +503,14 @@ public static function integer($value): bool
*/
public static function ip($value, string $type = 'both'): bool
{
$map = ['both' => 0, 'ipv4' => FILTER_FLAG_IPV4, 'ipv6' => FILTER_FLAG_IPV6];
$options = ['flags' => $map[$type]];

return in_array($type, $map) && (bool) filter_var($value, FILTER_VALIDATE_IP, $options);
$flags = 0;
if($type === 'ipv4'){
$flags = FILTER_FLAG_IPV4;
}elseif($type === 'ipv6'){
$flags = FILTER_FLAG_IPV6;
}

return (bool) filter_var($value, FILTER_VALIDATE_IP, ['flags'=> $flags]);
}

/**
Expand Down

0 comments on commit a88d5b6

Please sign in to comment.