Skip to content

Commit 680d026

Browse files
committed
Merge pull request #136 from lsv/php7-reserved-names
[Proposal] new constraints name - for PHP7
2 parents 87b54b4 + dc310ac commit 680d026

13 files changed

+49
-49
lines changed

src/JsonSchema/Constraints/Collection.php renamed to src/JsonSchema/Constraints/CollectionConstraint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
namespace JsonSchema\Constraints;
1111

1212
/**
13-
* The Collection Constraints, validates an array against a given schema
13+
* The CollectionConstraint Constraints, validates an array against a given schema
1414
*
1515
* @author Robert Schönthal <[email protected]>
1616
* @author Bruno Prieto Reis <[email protected]>
1717
*/
18-
class Collection extends Constraint
18+
class CollectionConstraint extends Constraint
1919
{
2020
/**
2121
* {@inheritDoc}
@@ -104,7 +104,7 @@ protected function validateItems($value, $schema = null, $path = null, $i = null
104104
// Treat when we have more schema definitions than values, not for empty arrays
105105
if(count($value) > 0) {
106106
for ($k = count($value); $k < count($schema->items); $k++) {
107-
$this->checkUndefined(new Undefined(), $schema->items[$k], $path, $k);
107+
$this->checkUndefined(new UndefinedConstraint(), $schema->items[$k], $path, $k);
108108
}
109109
}
110110
}

src/JsonSchema/Constraints/Constraint.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ protected function incrementPath($path, $i)
137137
*/
138138
protected function checkArray($value, $schema = null, $path = null, $i = null)
139139
{
140-
$validator = new Collection($this->checkMode, $this->uriRetriever);
140+
$validator = new CollectionConstraint($this->checkMode, $this->uriRetriever);
141141
$validator->check($value, $schema, $path, $i);
142142

143143
$this->addErrors($validator->getErrors());
@@ -154,7 +154,7 @@ protected function checkArray($value, $schema = null, $path = null, $i = null)
154154
*/
155155
protected function checkObject($value, $schema = null, $path = null, $i = null, $patternProperties = null)
156156
{
157-
$validator = new Object($this->checkMode, $this->uriRetriever);
157+
$validator = new ObjectConstraint($this->checkMode, $this->uriRetriever);
158158
$validator->check($value, $schema, $path, $i, $patternProperties);
159159

160160
$this->addErrors($validator->getErrors());
@@ -170,7 +170,7 @@ protected function checkObject($value, $schema = null, $path = null, $i = null,
170170
*/
171171
protected function checkType($value, $schema = null, $path = null, $i = null)
172172
{
173-
$validator = new Type($this->checkMode, $this->uriRetriever);
173+
$validator = new TypeConstraint($this->checkMode, $this->uriRetriever);
174174
$validator->check($value, $schema, $path, $i);
175175

176176
$this->addErrors($validator->getErrors());
@@ -186,7 +186,7 @@ protected function checkType($value, $schema = null, $path = null, $i = null)
186186
*/
187187
protected function checkUndefined($value, $schema = null, $path = null, $i = null)
188188
{
189-
$validator = new Undefined($this->checkMode, $this->uriRetriever);
189+
$validator = new UndefinedConstraint($this->checkMode, $this->uriRetriever);
190190
$validator->check($value, $schema, $path, $i);
191191

192192
$this->addErrors($validator->getErrors());
@@ -202,7 +202,7 @@ protected function checkUndefined($value, $schema = null, $path = null, $i = nul
202202
*/
203203
protected function checkString($value, $schema = null, $path = null, $i = null)
204204
{
205-
$validator = new String($this->checkMode, $this->uriRetriever);
205+
$validator = new StringConstraint($this->checkMode, $this->uriRetriever);
206206
$validator->check($value, $schema, $path, $i);
207207

208208
$this->addErrors($validator->getErrors());
@@ -218,7 +218,7 @@ protected function checkString($value, $schema = null, $path = null, $i = null)
218218
*/
219219
protected function checkNumber($value, $schema = null, $path = null, $i = null)
220220
{
221-
$validator = new Number($this->checkMode, $this->uriRetriever);
221+
$validator = new NumberConstraint($this->checkMode, $this->uriRetriever);
222222
$validator->check($value, $schema, $path, $i);
223223

224224
$this->addErrors($validator->getErrors());
@@ -234,15 +234,15 @@ protected function checkNumber($value, $schema = null, $path = null, $i = null)
234234
*/
235235
protected function checkEnum($value, $schema = null, $path = null, $i = null)
236236
{
237-
$validator = new Enum($this->checkMode, $this->uriRetriever);
237+
$validator = new EnumConstraint($this->checkMode, $this->uriRetriever);
238238
$validator->check($value, $schema, $path, $i);
239239

240240
$this->addErrors($validator->getErrors());
241241
}
242242

243243
protected function checkFormat($value, $schema = null, $path = null, $i = null)
244244
{
245-
$validator = new Format($this->checkMode, $this->uriRetriever);
245+
$validator = new FormatConstraint($this->checkMode, $this->uriRetriever);
246246
$validator->check($value, $schema, $path, $i);
247247

248248
$this->addErrors($validator->getErrors());

src/JsonSchema/Constraints/Enum.php renamed to src/JsonSchema/Constraints/EnumConstraint.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010
namespace JsonSchema\Constraints;
1111

1212
/**
13-
* The Enum Constraints, validates an element against a given set of possibilities
13+
* The EnumConstraint Constraints, validates an element against a given set of possibilities
1414
*
1515
* @author Robert Schönthal <[email protected]>
1616
* @author Bruno Prieto Reis <[email protected]>
1717
*/
18-
class Enum extends Constraint
18+
class EnumConstraint extends Constraint
1919
{
2020
/**
2121
* {@inheritDoc}
2222
*/
2323
public function check($element, $schema = null, $path = null, $i = null)
2424
{
2525
// Only validate enum if the attribute exists
26-
if ($element instanceof Undefined && (!isset($schema->required) || !$schema->required)) {
26+
if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) {
2727
return;
2828
}
2929

src/JsonSchema/Constraints/Format.php renamed to src/JsonSchema/Constraints/FormatConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @author Justin Rainbow <[email protected]>
1616
* @link http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.23
1717
*/
18-
class Format extends Constraint
18+
class FormatConstraint extends Constraint
1919
{
2020
/**
2121
* {@inheritDoc}

src/JsonSchema/Constraints/Number.php renamed to src/JsonSchema/Constraints/NumberConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
namespace JsonSchema\Constraints;
1111

1212
/**
13-
* The Number Constraints, validates an number against a given schema
13+
* The NumberConstraint Constraints, validates an number against a given schema
1414
*
1515
* @author Robert Schönthal <[email protected]>
1616
* @author Bruno Prieto Reis <[email protected]>
1717
*/
18-
class Number extends Constraint
18+
class NumberConstraint extends Constraint
1919
{
2020
/**
2121
* {@inheritDoc}

src/JsonSchema/Constraints/Object.php renamed to src/JsonSchema/Constraints/ObjectConstraint.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
namespace JsonSchema\Constraints;
1111

1212
/**
13-
* The Object Constraints, validates an object against a given schema
13+
* The ObjectConstraint Constraints, validates an object against a given schema
1414
*
1515
* @author Robert Schönthal <[email protected]>
1616
* @author Bruno Prieto Reis <[email protected]>
1717
*/
18-
class Object extends Constraint
18+
class ObjectConstraint extends Constraint
1919
{
2020
/**
2121
* {@inheritDoc}
2222
*/
2323
function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null)
2424
{
25-
if ($element instanceof Undefined) {
25+
if ($element instanceof UndefinedConstraint) {
2626
return;
2727
}
2828

@@ -64,15 +64,15 @@ public function validatePatternProperties($element, $path, $patternProperties)
6464
*
6565
* @param \stdClass $element Element to validate
6666
* @param array $matches Matches from patternProperties (if any)
67-
* @param \stdClass $objectDefinition Object definition
67+
* @param \stdClass $objectDefinition ObjectConstraint definition
6868
* @param string $path Path to test?
6969
* @param mixed $additionalProp Additional properties
7070
*/
7171
public function validateElement($element, $matches, $objectDefinition = null, $path = null, $additionalProp = null)
7272
{
7373
foreach ($element as $i => $value) {
7474

75-
$property = $this->getProperty($element, $i, new Undefined());
75+
$property = $this->getProperty($element, $i, new UndefinedConstraint());
7676
$definition = $this->getProperty($objectDefinition, $i);
7777

7878
// no additional properties allowed
@@ -106,13 +106,13 @@ public function validateElement($element, $matches, $objectDefinition = null, $p
106106
* Validates the definition properties
107107
*
108108
* @param \stdClass $element Element to validate
109-
* @param \stdClass $objectDefinition Object definition
109+
* @param \stdClass $objectDefinition ObjectConstraint definition
110110
* @param string $path Path?
111111
*/
112112
public function validateDefinition($element, $objectDefinition = null, $path = null)
113113
{
114114
foreach ($objectDefinition as $i => $value) {
115-
$property = $this->getProperty($element, $i, new Undefined());
115+
$property = $this->getProperty($element, $i, new UndefinedConstraint());
116116
$definition = $this->getProperty($objectDefinition, $i);
117117
$this->checkUndefined($property, $definition, $path, $i);
118118
}

src/JsonSchema/Constraints/Schema.php renamed to src/JsonSchema/Constraints/SchemaConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
use JsonSchema\Exception\InvalidArgumentException;
1313

1414
/**
15-
* The Schema Constraints, validates an element against a given schema
15+
* The SchemaConstraint Constraints, validates an element against a given schema
1616
*
1717
* @author Robert Schönthal <[email protected]>
1818
* @author Bruno Prieto Reis <[email protected]>
1919
*/
20-
class Schema extends Constraint
20+
class SchemaConstraint extends Constraint
2121
{
2222
/**
2323
* {@inheritDoc}

src/JsonSchema/Constraints/String.php renamed to src/JsonSchema/Constraints/StringConstraint.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
namespace JsonSchema\Constraints;
1111

1212
/**
13-
* The String Constraints, validates an string against a given schema
13+
* The StringConstraint Constraints, validates an string against a given schema
1414
*
1515
* @author Robert Schönthal <[email protected]>
1616
* @author Bruno Prieto Reis <[email protected]>
1717
*/
18-
class String extends Constraint
18+
class StringConstraint extends Constraint
1919
{
2020
/**
2121
* {@inheritDoc}

src/JsonSchema/Constraints/Type.php renamed to src/JsonSchema/Constraints/TypeConstraint.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
use UnexpectedValueException as StandardUnexpectedValueException;
1414

1515
/**
16-
* The Type Constraints, validates an element against a given type
16+
* The TypeConstraint Constraints, validates an element against a given type
1717
*
1818
* @author Robert Schönthal <[email protected]>
1919
* @author Bruno Prieto Reis <[email protected]>
2020
*/
21-
class Type extends Constraint
21+
class TypeConstraint extends Constraint
2222
{
2323
/**
2424
* @var array|string[] type wordings for validation error messages
@@ -48,7 +48,7 @@ public function check($value = null, $schema = null, $path = null, $i = null)
4848
$validatedOneType = false;
4949
$errors = array();
5050
foreach ($type as $tp) {
51-
$validator = new Type($this->checkMode);
51+
$validator = new TypeConstraint($this->checkMode);
5252
$subSchema = new \stdClass();
5353
$subSchema->type = $tp;
5454
$validator->check($value, $subSchema, $path, null);
@@ -88,7 +88,7 @@ public function check($value = null, $schema = null, $path = null, $i = null)
8888
* Verifies that a given value is of a certain type
8989
*
9090
* @param mixed $value Value to validate
91-
* @param string $type Type to check against
91+
* @param string $type TypeConstraint to check against
9292
*
9393
* @return boolean
9494
*

src/JsonSchema/Constraints/Undefined.php renamed to src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
use JsonSchema\Uri\UriResolver;
1414

1515
/**
16-
* The Undefined Constraints
16+
* The UndefinedConstraint Constraints
1717
*
1818
* @author Robert Schönthal <[email protected]>
1919
* @author Bruno Prieto Reis <[email protected]>
2020
*/
21-
class Undefined extends Constraint
21+
class UndefinedConstraint extends Constraint
2222
{
2323
/**
2424
* {@inheritDoc}
@@ -118,7 +118,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null
118118
// Verify required values
119119
if (is_object($value)) {
120120

121-
if (!($value instanceof Undefined) && isset($schema->required) && is_array($schema->required) ) {
121+
if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required) ) {
122122
// Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...]
123123
foreach ($schema->required as $required) {
124124
if (!property_exists($value, $required)) {
@@ -127,14 +127,14 @@ protected function validateCommonProperties($value, $schema = null, $path = null
127127
}
128128
} else if (isset($schema->required) && !is_array($schema->required)) {
129129
// Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true}
130-
if ( $schema->required && $value instanceof Undefined) {
130+
if ( $schema->required && $value instanceof UndefinedConstraint) {
131131
$this->addError($path, "is missing and it is required");
132132
}
133133
}
134134
}
135135

136136
// Verify type
137-
if (!($value instanceof Undefined)) {
137+
if (!($value instanceof UndefinedConstraint)) {
138138
$this->checkType($value, $schema, $path);
139139
}
140140

@@ -197,7 +197,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null
197197
protected function validateOfProperties($value, $schema, $path, $i = "")
198198
{
199199
// Verify type
200-
if ($value instanceof Undefined) {
200+
if ($value instanceof UndefinedConstraint) {
201201
return;
202202
}
203203

src/JsonSchema/Validator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace JsonSchema;
1111

12-
use JsonSchema\Constraints\Schema;
12+
use JsonSchema\Constraints\SchemaConstraint;
1313
use JsonSchema\Constraints\Constraint;
1414

1515
use JsonSchema\Exception\InvalidSchemaMediaTypeException;
@@ -37,7 +37,7 @@ class Validator extends Constraint
3737
*/
3838
public function check($value, $schema = null, $path = null, $i = null)
3939
{
40-
$validator = new Schema($this->checkMode, $this->uriRetriever);
40+
$validator = new SchemaConstraint($this->checkMode, $this->uriRetriever);
4141
$validator->check($value, $schema);
4242

4343
$this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR));

tests/JsonSchema/Tests/Constraints/FormatTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace JsonSchema\Tests\Constraints;
1111

12-
use JsonSchema\Constraints\Format;
12+
use JsonSchema\Constraints\FormatConstraint;
1313

1414
class FormatTest extends BaseTestCase
1515
{
@@ -20,7 +20,7 @@ public function setUp()
2020

2121
public function testNullThing()
2222
{
23-
$validator = new Format();
23+
$validator = new FormatConstraint();
2424
$schema = new \stdClass;
2525

2626
$validator->check('10', $schema);
@@ -29,7 +29,7 @@ public function testNullThing()
2929

3030
public function testRegex()
3131
{
32-
$validator = new Format();
32+
$validator = new FormatConstraint();
3333
$schema = new \stdClass;
3434
$schema->format = 'regex';
3535

@@ -45,7 +45,7 @@ public function testRegex()
4545
*/
4646
public function testValidFormat($string, $format)
4747
{
48-
$validator = new Format();
48+
$validator = new FormatConstraint();
4949
$schema = new \stdClass;
5050
$schema->format = $format;
5151

@@ -58,7 +58,7 @@ public function testValidFormat($string, $format)
5858
*/
5959
public function testInvalidFormat($string, $format)
6060
{
61-
$validator = new Format();
61+
$validator = new FormatConstraint();
6262
$schema = new \stdClass;
6363
$schema->format = $format;
6464

0 commit comments

Comments
 (0)