Skip to content

Commit 0491e13

Browse files
committed
Remove Validator::coerce()
1 parent 92d16b5 commit 0491e13

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

src/JsonSchema/Validator.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class Validator extends BaseConstraint
2626
/**
2727
* Validates the given data against the schema and returns an object containing the results
2828
* Both the php object and the schema are supposed to be a result of a json_decode call.
29-
* The validation works as defined by the schema proposal in http://json-schema.org
29+
* The validation works as defined by the schema proposal in http://json-schema.org.
30+
*
31+
* Note that the first argument is passwd by reference, so you must pass in a variable.
3032
*
3133
* {@inheritDoc}
3234
*/
@@ -42,16 +44,4 @@ public function check(&$value, $schema = null, array $config = array())
4244

4345
$this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR));
4446
}
45-
46-
/**
47-
* Does everything that check does, but will also coerce string values in the input to their expected
48-
* types defined in the schema whenever possible. Note that the first argument is passed by reference,
49-
* so you must pass in a variable.
50-
*
51-
* {@inheritDoc}
52-
*/
53-
public function coerce(&$value, $schema = null)
54-
{
55-
return $this->check($value, $schema, array('coerce-types' => true));
56-
}
5747
}

tests/Constraints/CoerciveTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testValidCoerceCasesUsingAssoc($input, $schema)
3131

3232
$value = json_decode($input, true);
3333

34-
$validator->coerce($value, $schema);
34+
$validator->check($value, $schema, array('coerce-types' => true));
3535
$this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
3636
}
3737

@@ -52,7 +52,7 @@ public function testValidCoerceCases($input, $schema, $errors = array())
5252
$this->assertTrue(gettype($value->integer) == "string");
5353
$this->assertTrue(gettype($value->boolean) == "string");
5454

55-
$validator->coerce($value, $schema);
55+
$validator->check($value, $schema, array('coerce-types' => true));
5656

5757
$this->assertTrue(gettype($value->number) == "double");
5858
$this->assertTrue(gettype($value->integer) == "integer");
@@ -88,7 +88,7 @@ public function testInvalidCoerceCases($input, $schema, $errors = array())
8888

8989
$validator = new Validator(new Factory($schemaStorage, null, array('checkMode' => $checkMode)));
9090
$value = json_decode($input);
91-
$validator->coerce($value, $schema);
91+
$validator->check($value, $schema, array('coerce-types' => true));
9292

9393
if (array() !== $errors) {
9494
$this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true));
@@ -108,7 +108,7 @@ public function testInvalidCoerceCasesUsingAssoc($input, $schema, $errors = arra
108108

109109
$validator = new Validator(new Factory($schemaStorage, null, array('checkMode' => $checkMode)));
110110
$value = json_decode($input, true);
111-
$validator->coerce($value, $schema);
111+
$validator->check($value, $schema, array('coerce-types' => true));
112112

113113
if (array() !== $errors) {
114114
$this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true));

0 commit comments

Comments
 (0)