Skip to content

Commit

Permalink
Fixed numeric validation, now uses is_numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
jamielsharief committed Jul 26, 2021
1 parent 77bf0a0 commit 57b9ecd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.1] - 2021-07-26

### Fixed

- Fixed numeric validation, now uses `is_numeric`

## [2.0.0] - 2021-01-04

Expand Down
13 changes: 6 additions & 7 deletions src/Validation.php
Expand Up @@ -356,7 +356,6 @@ public static function greaterThanOrEqual($value, $max): bool
return $value >= $max;
}


/**
* Validates a string only contains hexidecimal characters
*
Expand Down Expand Up @@ -504,13 +503,13 @@ public static function integer($value): bool
public static function ip($value, string $type = 'both'): bool
{
$flags = 0;
if($type === 'ipv4'){
if ($type === 'ipv4') {
$flags = FILTER_FLAG_IPV4;
}elseif($type === 'ipv6'){
} elseif ($type === 'ipv6') {
$flags = FILTER_FLAG_IPV6;
}

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

/**
Expand Down Expand Up @@ -640,6 +639,7 @@ public static function mimeType($result, $mimeTypes = []): bool
if (is_string($mimeTypes)) {
$mimeTypes = [$mimeTypes];
}

$mimeType = mime_content_type($result);
if ($mimeType === false) {
throw new Exception('Unable to determine the mimetype');
Expand Down Expand Up @@ -734,12 +734,12 @@ public static function notIn($value, array $list, bool $caseInSensitive = false)
/**
* Checks if a value is numeric (integer or float)
*
* @param int|float $value
* @param mixed $value
* @return boolean
*/
public static function numeric($value): bool
{
return (static::integer($value) || static::float($value));
return is_numeric($value);
}

/**
Expand Down Expand Up @@ -783,7 +783,6 @@ public static function regex($value, string $pattern): bool
return is_string($value) && (bool) preg_match($pattern, $value);
}


/**
* Validates a value is a string
*
Expand Down

0 comments on commit 57b9ecd

Please sign in to comment.