Skip to content

Commit

Permalink
Changed minLength & maxLength to work with non strings such as in…
Browse files Browse the repository at this point in the history
…tegers
  • Loading branch information
jamielsharief committed Jul 15, 2020
1 parent 973abab commit 952c32c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,15 @@ 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).



## [1.1.0] - 2020-07-15

## Changed

- Changed `minLength` to work with non strings such as integers
- Changed `maxLength` to work with non strings such as integers

## [1.0.2] - 2020-07-15

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions src/Validation.php
Expand Up @@ -595,7 +595,7 @@ public static function macAddress($value): bool
*/
public static function maxLength($value, int $max): bool
{
return (is_string($value) && mb_strlen($value) <= $max);
return (is_scalar($value) && mb_strlen((string) $value) <= $max);
}

/**
Expand Down Expand Up @@ -644,7 +644,7 @@ public static function mimeType($result, $mimeTypes = []): bool
*/
public static function minLength($value, int $min): bool
{
return (is_string($value) && mb_strlen($value) >= $min);
return (is_scalar($value) && mb_strlen((string) $value) >= $min);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/ValidationTest.php
Expand Up @@ -405,12 +405,20 @@ public function testMaxLength()
{
$this->assertTrue(Validation::maxLength('string', 10));
$this->assertFalse(Validation::maxLength('string', 3));

$this->assertTrue(Validation::maxLength(123456, 8));
$this->assertFalse(Validation::maxLength(123456, 4));
$this->assertFalse(Validation::maxLength(null, 3));
}

public function testMinLength()
{
$this->assertTrue(Validation::minLength('password', 8));
$this->assertFalse(Validation::minLength('nada', 8));

$this->assertTrue(Validation::minLength(123456, 4));
$this->assertFalse(Validation::minLength(123456, 8));
$this->assertFalse(Validation::minLength(null, 3));
}
public function testNotBlank()
{
Expand Down

0 comments on commit 952c32c

Please sign in to comment.