Skip to content

[Proposal] new constraints name - for PHP7 #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
class Collection extends Constraint
class CollectionConstraint extends Constraint
{
/**
* {@inheritDoc}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/JsonSchema/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -234,15 +234,15 @@ 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());
}

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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
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 <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
class Enum extends Constraint
class EnumConstraint extends Constraint
{
/**
* {@inheritDoc}
*/
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Justin Rainbow <[email protected]>
* @link http://tools.ietf.org/html/draft-zyp-json-schema-03#section-5.23
*/
class Format extends Constraint
class FormatConstraint extends Constraint
{
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
class Number extends Constraint
class NumberConstraint extends Constraint
{
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
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;
}

Expand Down Expand Up @@ -64,15 +64,15 @@ 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
*/
public function validateElement($element, $matches, $objectDefinition = null, $path = null, $additionalProp = null)
{
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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
class Schema extends Constraint
class SchemaConstraint extends Constraint
{
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
class String extends Constraint
class StringConstraint extends Constraint
{
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
class Type extends Constraint
class TypeConstraint extends Constraint
{
/**
* @var array|string[] type wordings for validation error messages
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
use JsonSchema\Uri\UriResolver;

/**
* The Undefined Constraints
* The UndefinedConstraint Constraints
*
* @author Robert Schönthal <[email protected]>
* @author Bruno Prieto Reis <[email protected]>
*/
class Undefined extends Constraint
class UndefinedConstraint extends Constraint
{
/**
* {@inheritDoc}
Expand Down Expand Up @@ -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)) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/JsonSchema/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace JsonSchema;

use JsonSchema\Constraints\Schema;
use JsonSchema\Constraints\SchemaConstraint;
use JsonSchema\Constraints\Constraint;

use JsonSchema\Exception\InvalidSchemaMediaTypeException;
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 5 additions & 5 deletions tests/JsonSchema/Tests/Constraints/FormatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace JsonSchema\Tests\Constraints;

use JsonSchema\Constraints\Format;
use JsonSchema\Constraints\FormatConstraint;

class FormatTest extends BaseTestCase
{
Expand All @@ -20,7 +20,7 @@ public function setUp()

public function testNullThing()
{
$validator = new Format();
$validator = new FormatConstraint();
$schema = new \stdClass;

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

public function testRegex()
{
$validator = new Format();
$validator = new FormatConstraint();
$schema = new \stdClass;
$schema->format = 'regex';

Expand All @@ -45,7 +45,7 @@ public function testRegex()
*/
public function testValidFormat($string, $format)
{
$validator = new Format();
$validator = new FormatConstraint();
$schema = new \stdClass;
$schema->format = $format;

Expand All @@ -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;

Expand Down
Loading