Skip to content

Commit 360eda9

Browse files
committed
Change strict mode to be an argument of matches()
1 parent a5a9bcc commit 360eda9

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

src/Validator.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@ class Validator
1414

1515
/**
1616
* Constructor.
17-
*
18-
* @param $options
1917
*/
20-
public function __construct(array $options = [])
18+
public function __construct()
2119
{
22-
$this->strict = $options['strict'] ?? false;
23-
2420
$this->types = $this->getBuiltInTypeValidators();
2521
}
2622

@@ -139,12 +135,15 @@ protected function reset()
139135
*
140136
* @param $data
141137
* @param $type
138+
* @param $strict
142139
* @return bool
143140
*/
144-
public function matches($data, $type)
141+
public function matches($data, $type, $strict = false)
145142
{
146143
$this->reset();
147144

145+
$this->strict = $strict;
146+
148147
return $this->matchInternal($data, $type);
149148
}
150149

tests/JsonTypeTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
*/
1313
class JsonTypeTest extends PHPUnit_Framework_TestCase
1414
{
15-
protected function createValidator($strictMode = false)
15+
protected function createValidator()
1616
{
17-
$validator = new Validator(['strict' => $strictMode]);
17+
$validator = new Validator();
1818

1919
$validator->addType('timestamp', $this->timestampValidator());
2020

@@ -223,9 +223,9 @@ public function typeStrictData()
223223
*/
224224
public function testStrictMode($value, $type, $key, $message)
225225
{
226-
$json = $this->createValidator(true);
226+
$json = $this->createValidator();
227227

228-
$this->assertFalse($json->matches($value, $type));
228+
$this->assertFalse($json->matches($value, $type, true));
229229
$this->assertEquals($message, $json->getErrors()[$key] ?? '');
230230
}
231231

0 commit comments

Comments
 (0)