Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 52a1bef

Browse files
committed
Merge pull request #187 from weierophinney/hotfix/183
Ensure Between validator has both min and max values during construction
2 parents 39bd051 + 8a80fc8 commit 52a1bef

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

src/Between.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,17 @@ public function __construct($options = null)
9090
$options = $temp;
9191
}
9292

93-
if (count($options) !== 2
94-
&& (! array_key_exists('min', $options) || ! array_key_exists('max', $options))
95-
) {
93+
if (! array_key_exists('min', $options) || ! array_key_exists('max', $options)) {
9694
throw new Exception\InvalidArgumentException("Missing option: 'min' and 'max' have to be given");
9795
}
9896

99-
if (is_numeric($options['min']) && is_numeric($options['max'])) {
97+
if ((isset($options['min']) && is_numeric($options['min']))
98+
&& (isset($options['max']) && is_numeric($options['max']))
99+
) {
100100
$this->numeric = true;
101-
} elseif (is_string($options['min']) && is_string($options['max'])) {
101+
} elseif ((isset($options['min']) && is_string($options['min']))
102+
&& (isset($options['max']) && is_string($options['max']))
103+
) {
102104
$this->numeric = false;
103105
} else {
104106
throw new Exception\InvalidArgumentException(

test/BetweenTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,13 @@ public function testMissingMinOrMax(array $args)
265265
public function constructBetweenValidatorInvalidDataProvider()
266266
{
267267
return [
268-
[
269-
['min' => 1],
270-
],
271-
[
272-
['max' => 5],
273-
],
268+
'only-min' => [['min' => 1]],
269+
'only-max' => [['max' => 5]],
270+
'min-inclusive' => [['min' => 0, 'inclusive' => true]],
271+
'max-inclusive' => [['max' => 5, 'inclusive' => true]],
272+
'min-undefined' => [['min' => 0, 'foo' => 'bar']],
273+
'max-undefined' => [['max' => 5, 'foo' => 'bar']],
274+
'no-min-or-max' => [['bar' => 'foo', 'foo' => 'bar']],
274275
];
275276
}
276277

0 commit comments

Comments
 (0)