Skip to content

Code cleanup #55

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 4 commits into from
Jul 22, 2013
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
12 changes: 6 additions & 6 deletions src/JsonSchema/Constraints/Constraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace JsonSchema\Constraints;

use JsonSchema\Uri;
use JsonSchema\Uri\UriRetriever;

/**
* The Base Constraints, all Validators should extend this class
Expand All @@ -31,7 +31,7 @@ abstract class Constraint implements ConstraintInterface
* @param int $checkMode
* @param UriRetriever $uriRetriever
*/
public function __construct($checkMode = self::CHECK_MODE_NORMAL, \JsonSchema\Uri\UriRetriever $uriRetriever = null)
public function __construct($checkMode = self::CHECK_MODE_NORMAL, UriRetriever $uriRetriever = null)
{
$this->checkMode = $checkMode;
$this->uriRetriever = $uriRetriever;
Expand All @@ -40,11 +40,11 @@ public function __construct($checkMode = self::CHECK_MODE_NORMAL, \JsonSchema\Ur
/**
* @return UriRetriever $uriRetriever
*/
public function getUriRetriever()
public function getUriRetriever()
{
if (is_null($this->uriRetriever))
{
$this->setUriRetriever(new \JsonSchema\Uri\UriRetriever);
$this->setUriRetriever(new UriRetriever);
}

return $this->uriRetriever;
Expand All @@ -53,7 +53,7 @@ public function getUriRetriever()
/**
* @param UriRetriever $uriRetriever
*/
public function setUriRetriever(\JsonSchema\Uri\UriRetriever $uriRetriever)
public function setUriRetriever(UriRetriever $uriRetriever)
{
$this->uriRetriever = $uriRetriever;
}
Expand Down Expand Up @@ -255,7 +255,7 @@ protected function checkFormat($value, $schema = null, $path = null, $i = null)
protected function retrieveUri($uri)
{
if (null === $this->uriRetriever) {
$this->setUriRetriever(new \JsonSchema\Uri\UriRetriever);
$this->setUriRetriever(new UriRetriever);
}
$jsonSchema = $this->uriRetriever->retrieve($uri);
// TODO validate using schema
Expand Down
13 changes: 5 additions & 8 deletions src/JsonSchema/Constraints/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ public function validateElement($element, $matches, $objectDefinition = null, $p
$property = $this->getProperty($element, $i, new Undefined());
$definition = $this->getProperty($objectDefinition, $i);

//required property
if ($this->getProperty($definition, 'required') && $property instanceof Undefined) {
$this->addError($path, "the property " . $i . " is required");
}

//no additional properties allowed
// no additional properties allowed
if (!in_array($i, $matches) && $additionalProp === false && $this->inlineSchemaProperty !== $i && !$definition) {
$this->addError($path, "The property " . $i . " is not defined and the definition does not allow additional properties");
}
Expand All @@ -96,8 +91,10 @@ public function validateElement($element, $matches, $objectDefinition = null, $p
$this->addError($path, "the presence of the property " . $i . " requires that " . $require . " also be present");
}

//normal property verification
$this->checkUndefined($value, $definition ? : new \stdClass(), $path, $i);
if (!$definition) {
// normal property verification
$this->checkUndefined($value, new \stdClass(), $path, $i);
}
}
}

Expand Down