diff --git a/src/JsonSchema/Constraints/Collection.php b/src/JsonSchema/Constraints/CollectionConstraint.php similarity index 94% rename from src/JsonSchema/Constraints/Collection.php rename to src/JsonSchema/Constraints/CollectionConstraint.php index 079617c4..7de3bc4d 100644 --- a/src/JsonSchema/Constraints/Collection.php +++ b/src/JsonSchema/Constraints/CollectionConstraint.php @@ -10,12 +10,12 @@ namespace JsonSchema\Constraints; /** - * The Collection Constraints, validates an array against a given schema + * The CollectionConstraint Constraints, validates an array against a given schema * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class Collection extends Constraint +class CollectionConstraint extends Constraint { /** * {@inheritDoc} @@ -104,7 +104,7 @@ protected function validateItems($value, $schema = null, $path = null, $i = null // Treat when we have more schema definitions than values, not for empty arrays if(count($value) > 0) { for ($k = count($value); $k < count($schema->items); $k++) { - $this->checkUndefined(new Undefined(), $schema->items[$k], $path, $k); + $this->checkUndefined(new UndefinedConstraint(), $schema->items[$k], $path, $k); } } } diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index 889e4ecb..b7781bc9 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -137,7 +137,7 @@ protected function incrementPath($path, $i) */ protected function checkArray($value, $schema = null, $path = null, $i = null) { - $validator = new Collection($this->checkMode, $this->uriRetriever); + $validator = new CollectionConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i); $this->addErrors($validator->getErrors()); @@ -154,7 +154,7 @@ protected function checkArray($value, $schema = null, $path = null, $i = null) */ protected function checkObject($value, $schema = null, $path = null, $i = null, $patternProperties = null) { - $validator = new Object($this->checkMode, $this->uriRetriever); + $validator = new ObjectConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i, $patternProperties); $this->addErrors($validator->getErrors()); @@ -170,7 +170,7 @@ protected function checkObject($value, $schema = null, $path = null, $i = null, */ protected function checkType($value, $schema = null, $path = null, $i = null) { - $validator = new Type($this->checkMode, $this->uriRetriever); + $validator = new TypeConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i); $this->addErrors($validator->getErrors()); @@ -186,7 +186,7 @@ protected function checkType($value, $schema = null, $path = null, $i = null) */ protected function checkUndefined($value, $schema = null, $path = null, $i = null) { - $validator = new Undefined($this->checkMode, $this->uriRetriever); + $validator = new UndefinedConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i); $this->addErrors($validator->getErrors()); @@ -202,7 +202,7 @@ protected function checkUndefined($value, $schema = null, $path = null, $i = nul */ protected function checkString($value, $schema = null, $path = null, $i = null) { - $validator = new String($this->checkMode, $this->uriRetriever); + $validator = new StringConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i); $this->addErrors($validator->getErrors()); @@ -218,7 +218,7 @@ protected function checkString($value, $schema = null, $path = null, $i = null) */ protected function checkNumber($value, $schema = null, $path = null, $i = null) { - $validator = new Number($this->checkMode, $this->uriRetriever); + $validator = new NumberConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i); $this->addErrors($validator->getErrors()); @@ -234,7 +234,7 @@ protected function checkNumber($value, $schema = null, $path = null, $i = null) */ protected function checkEnum($value, $schema = null, $path = null, $i = null) { - $validator = new Enum($this->checkMode, $this->uriRetriever); + $validator = new EnumConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i); $this->addErrors($validator->getErrors()); @@ -242,7 +242,7 @@ protected function checkEnum($value, $schema = null, $path = null, $i = null) protected function checkFormat($value, $schema = null, $path = null, $i = null) { - $validator = new Format($this->checkMode, $this->uriRetriever); + $validator = new FormatConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema, $path, $i); $this->addErrors($validator->getErrors()); diff --git a/src/JsonSchema/Constraints/Enum.php b/src/JsonSchema/Constraints/EnumConstraint.php similarity index 77% rename from src/JsonSchema/Constraints/Enum.php rename to src/JsonSchema/Constraints/EnumConstraint.php index c80a2d55..e0bea651 100644 --- a/src/JsonSchema/Constraints/Enum.php +++ b/src/JsonSchema/Constraints/EnumConstraint.php @@ -10,12 +10,12 @@ namespace JsonSchema\Constraints; /** - * The Enum Constraints, validates an element against a given set of possibilities + * The EnumConstraint Constraints, validates an element against a given set of possibilities * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class Enum extends Constraint +class EnumConstraint extends Constraint { /** * {@inheritDoc} @@ -23,7 +23,7 @@ class Enum extends Constraint public function check($element, $schema = null, $path = null, $i = null) { // Only validate enum if the attribute exists - if ($element instanceof Undefined && (!isset($schema->required) || !$schema->required)) { + if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) { return; } diff --git a/src/JsonSchema/Constraints/Format.php b/src/JsonSchema/Constraints/FormatConstraint.php similarity index 99% rename from src/JsonSchema/Constraints/Format.php rename to src/JsonSchema/Constraints/FormatConstraint.php index 9bcab3eb..d939f962 100644 --- a/src/JsonSchema/Constraints/Format.php +++ b/src/JsonSchema/Constraints/FormatConstraint.php @@ -15,7 +15,7 @@ * @author Justin Rainbow * @link http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.23 */ -class Format extends Constraint +class FormatConstraint extends Constraint { /** * {@inheritDoc} diff --git a/src/JsonSchema/Constraints/Number.php b/src/JsonSchema/Constraints/NumberConstraint.php similarity index 96% rename from src/JsonSchema/Constraints/Number.php rename to src/JsonSchema/Constraints/NumberConstraint.php index b5a7d834..49bfbbba 100644 --- a/src/JsonSchema/Constraints/Number.php +++ b/src/JsonSchema/Constraints/NumberConstraint.php @@ -10,12 +10,12 @@ namespace JsonSchema\Constraints; /** - * The Number Constraints, validates an number against a given schema + * The NumberConstraint Constraints, validates an number against a given schema * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class Number extends Constraint +class NumberConstraint extends Constraint { /** * {@inheritDoc} diff --git a/src/JsonSchema/Constraints/Object.php b/src/JsonSchema/Constraints/ObjectConstraint.php similarity index 93% rename from src/JsonSchema/Constraints/Object.php rename to src/JsonSchema/Constraints/ObjectConstraint.php index e9fc29e5..9dc0b188 100644 --- a/src/JsonSchema/Constraints/Object.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -10,19 +10,19 @@ namespace JsonSchema\Constraints; /** - * The Object Constraints, validates an object against a given schema + * The ObjectConstraint Constraints, validates an object against a given schema * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class Object extends Constraint +class ObjectConstraint extends Constraint { /** * {@inheritDoc} */ function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null) { - if ($element instanceof Undefined) { + if ($element instanceof UndefinedConstraint) { return; } @@ -64,7 +64,7 @@ public function validatePatternProperties($element, $path, $patternProperties) * * @param \stdClass $element Element to validate * @param array $matches Matches from patternProperties (if any) - * @param \stdClass $objectDefinition Object definition + * @param \stdClass $objectDefinition ObjectConstraint definition * @param string $path Path to test? * @param mixed $additionalProp Additional properties */ @@ -72,7 +72,7 @@ public function validateElement($element, $matches, $objectDefinition = null, $p { foreach ($element as $i => $value) { - $property = $this->getProperty($element, $i, new Undefined()); + $property = $this->getProperty($element, $i, new UndefinedConstraint()); $definition = $this->getProperty($objectDefinition, $i); // no additional properties allowed @@ -106,13 +106,13 @@ public function validateElement($element, $matches, $objectDefinition = null, $p * Validates the definition properties * * @param \stdClass $element Element to validate - * @param \stdClass $objectDefinition Object definition + * @param \stdClass $objectDefinition ObjectConstraint definition * @param string $path Path? */ public function validateDefinition($element, $objectDefinition = null, $path = null) { foreach ($objectDefinition as $i => $value) { - $property = $this->getProperty($element, $i, new Undefined()); + $property = $this->getProperty($element, $i, new UndefinedConstraint()); $definition = $this->getProperty($objectDefinition, $i); $this->checkUndefined($property, $definition, $path, $i); } diff --git a/src/JsonSchema/Constraints/Schema.php b/src/JsonSchema/Constraints/SchemaConstraint.php similarity index 88% rename from src/JsonSchema/Constraints/Schema.php rename to src/JsonSchema/Constraints/SchemaConstraint.php index 595ca436..b856a114 100644 --- a/src/JsonSchema/Constraints/Schema.php +++ b/src/JsonSchema/Constraints/SchemaConstraint.php @@ -12,12 +12,12 @@ use JsonSchema\Exception\InvalidArgumentException; /** - * The Schema Constraints, validates an element against a given schema + * The SchemaConstraint Constraints, validates an element against a given schema * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class Schema extends Constraint +class SchemaConstraint extends Constraint { /** * {@inheritDoc} diff --git a/src/JsonSchema/Constraints/String.php b/src/JsonSchema/Constraints/StringConstraint.php similarity index 92% rename from src/JsonSchema/Constraints/String.php rename to src/JsonSchema/Constraints/StringConstraint.php index 246c06b4..a4cd3745 100644 --- a/src/JsonSchema/Constraints/String.php +++ b/src/JsonSchema/Constraints/StringConstraint.php @@ -10,12 +10,12 @@ namespace JsonSchema\Constraints; /** - * The String Constraints, validates an string against a given schema + * The StringConstraint Constraints, validates an string against a given schema * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class String extends Constraint +class StringConstraint extends Constraint { /** * {@inheritDoc} diff --git a/src/JsonSchema/Constraints/Type.php b/src/JsonSchema/Constraints/TypeConstraint.php similarity index 94% rename from src/JsonSchema/Constraints/Type.php rename to src/JsonSchema/Constraints/TypeConstraint.php index 5fc80a42..3c439d54 100644 --- a/src/JsonSchema/Constraints/Type.php +++ b/src/JsonSchema/Constraints/TypeConstraint.php @@ -13,12 +13,12 @@ use UnexpectedValueException as StandardUnexpectedValueException; /** - * The Type Constraints, validates an element against a given type + * The TypeConstraint Constraints, validates an element against a given type * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class Type extends Constraint +class TypeConstraint extends Constraint { /** * @var array|string[] type wordings for validation error messages @@ -48,7 +48,7 @@ public function check($value = null, $schema = null, $path = null, $i = null) $validatedOneType = false; $errors = array(); foreach ($type as $tp) { - $validator = new Type($this->checkMode); + $validator = new TypeConstraint($this->checkMode); $subSchema = new \stdClass(); $subSchema->type = $tp; $validator->check($value, $subSchema, $path, null); @@ -88,7 +88,7 @@ public function check($value = null, $schema = null, $path = null, $i = null) * Verifies that a given value is of a certain type * * @param mixed $value Value to validate - * @param string $type Type to check against + * @param string $type TypeConstraint to check against * * @return boolean * diff --git a/src/JsonSchema/Constraints/Undefined.php b/src/JsonSchema/Constraints/UndefinedConstraint.php similarity index 96% rename from src/JsonSchema/Constraints/Undefined.php rename to src/JsonSchema/Constraints/UndefinedConstraint.php index e632de5e..8527b9db 100644 --- a/src/JsonSchema/Constraints/Undefined.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -13,12 +13,12 @@ use JsonSchema\Uri\UriResolver; /** - * The Undefined Constraints + * The UndefinedConstraint Constraints * * @author Robert Schönthal * @author Bruno Prieto Reis */ -class Undefined extends Constraint +class UndefinedConstraint extends Constraint { /** * {@inheritDoc} @@ -118,7 +118,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null // Verify required values if (is_object($value)) { - if (!($value instanceof Undefined) && isset($schema->required) && is_array($schema->required) ) { + if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required) ) { // Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...] foreach ($schema->required as $required) { if (!property_exists($value, $required)) { @@ -127,14 +127,14 @@ protected function validateCommonProperties($value, $schema = null, $path = null } } else if (isset($schema->required) && !is_array($schema->required)) { // Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true} - if ( $schema->required && $value instanceof Undefined) { + if ( $schema->required && $value instanceof UndefinedConstraint) { $this->addError($path, "is missing and it is required"); } } } // Verify type - if (!($value instanceof Undefined)) { + if (!($value instanceof UndefinedConstraint)) { $this->checkType($value, $schema, $path); } @@ -197,7 +197,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null protected function validateOfProperties($value, $schema, $path, $i = "") { // Verify type - if ($value instanceof Undefined) { + if ($value instanceof UndefinedConstraint) { return; } diff --git a/src/JsonSchema/Validator.php b/src/JsonSchema/Validator.php index 70d4bfbf..935311bb 100644 --- a/src/JsonSchema/Validator.php +++ b/src/JsonSchema/Validator.php @@ -9,7 +9,7 @@ namespace JsonSchema; -use JsonSchema\Constraints\Schema; +use JsonSchema\Constraints\SchemaConstraint; use JsonSchema\Constraints\Constraint; use JsonSchema\Exception\InvalidSchemaMediaTypeException; @@ -37,7 +37,7 @@ class Validator extends Constraint */ public function check($value, $schema = null, $path = null, $i = null) { - $validator = new Schema($this->checkMode, $this->uriRetriever); + $validator = new SchemaConstraint($this->checkMode, $this->uriRetriever); $validator->check($value, $schema); $this->addErrors(array_unique($validator->getErrors(), SORT_REGULAR)); diff --git a/tests/JsonSchema/Tests/Constraints/FormatTest.php b/tests/JsonSchema/Tests/Constraints/FormatTest.php index b9d4e54f..f5d8d18e 100644 --- a/tests/JsonSchema/Tests/Constraints/FormatTest.php +++ b/tests/JsonSchema/Tests/Constraints/FormatTest.php @@ -9,7 +9,7 @@ namespace JsonSchema\Tests\Constraints; -use JsonSchema\Constraints\Format; +use JsonSchema\Constraints\FormatConstraint; class FormatTest extends BaseTestCase { @@ -20,7 +20,7 @@ public function setUp() public function testNullThing() { - $validator = new Format(); + $validator = new FormatConstraint(); $schema = new \stdClass; $validator->check('10', $schema); @@ -29,7 +29,7 @@ public function testNullThing() public function testRegex() { - $validator = new Format(); + $validator = new FormatConstraint(); $schema = new \stdClass; $schema->format = 'regex'; @@ -45,7 +45,7 @@ public function testRegex() */ public function testValidFormat($string, $format) { - $validator = new Format(); + $validator = new FormatConstraint(); $schema = new \stdClass; $schema->format = $format; @@ -58,7 +58,7 @@ public function testValidFormat($string, $format) */ public function testInvalidFormat($string, $format) { - $validator = new Format(); + $validator = new FormatConstraint(); $schema = new \stdClass; $schema->format = $format; diff --git a/tests/JsonSchema/Tests/Constraints/TypeTest.php b/tests/JsonSchema/Tests/Constraints/TypeTest.php index aef76055..208049fb 100644 --- a/tests/JsonSchema/Tests/Constraints/TypeTest.php +++ b/tests/JsonSchema/Tests/Constraints/TypeTest.php @@ -9,7 +9,7 @@ namespace JsonSchema\Tests\Constraints; -use JsonSchema\Constraints\Type; +use JsonSchema\Constraints\TypeConstraint; /** * Class TypeTest @@ -41,7 +41,7 @@ public function provideIndefiniteArticlesForTypes() */ public function testIndefiniteArticleForTypeInTypeCheckErrorMessage($type, $wording, $value = null, $label = 'NULL') { - $constraint = new Type(); + $constraint = new TypeConstraint(); $constraint->check($value, (object)array('type' => $type)); $this->assertTypeConstraintError("$label value found, but $wording $type is required", $constraint); } @@ -50,9 +50,9 @@ public function testIndefiniteArticleForTypeInTypeCheckErrorMessage($type, $word * Helper to assert an error message * * @param string $expected - * @param Type $actual + * @param TypeConstraint $actual */ - private function assertTypeConstraintError($expected, Type $actual) + private function assertTypeConstraintError($expected, TypeConstraint $actual) { $actualErrors = $actual->getErrors();