Skip to content

Commit

Permalink
Merge 3503dd9
Browse files Browse the repository at this point in the history
  • Loading branch information
twose committed Apr 23, 2019
1 parent 4f8230b commit 5673808
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* @method static bool nullOrIp($value, $message = '')
* @method static bool nullOrIpv4($value, $message = '')
* @method static bool nullOrIpv6($value, $message = '')
* @method static bool nullOrUniqueValues($values, $message = '')
* @method static bool nullOrEq($value, $expect, $message = '')
* @method static bool nullOrNotEq($value, $expect, $message = '')
* @method static bool nullOrSame($value, $expect, $message = '')
Expand Down Expand Up @@ -130,6 +131,7 @@
* @method static bool allIp($values, $message = '')
* @method static bool allIpv4($values, $message = '')
* @method static bool allIpv6($values, $message = '')
* @method static bool allUniqueValues($values, $message = '')
* @method static bool allEq($values, $expect, $message = '')
* @method static bool allNotEq($values, $expect, $message = '')
* @method static bool allSame($values, $expect, $message = '')
Expand Down Expand Up @@ -544,6 +546,22 @@ public static function ipv6($value, $message = ''): bool
return true;
}

public static function uniqueValues(array $values, $message = ''): bool
{
$allValues = count($values);
$uniqueValues = count(array_unique($values));
if ($allValues !== $uniqueValues) {
$difference = $allValues - $uniqueValues;
static::reportInvalidArgument(sprintf(
$message ?: 'Expected an array of unique values, but %s of them %s duplicated',
$difference,
(1 === $difference ? 'is' : 'are')
));
return false;
}
return true;
}

public static function eq($value, $expect, $message = ''): bool
{
if ($expect != $value) {
Expand Down

0 comments on commit 5673808

Please sign in to comment.