Skip to content

Commit 9e5e903

Browse files
committed
Merge pull request #55 from alexmmm/code-cleanup
Code cleanup
2 parents f215683 + ed20d9f commit 9e5e903

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

src/JsonSchema/Constraints/Constraint.php

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

1010
namespace JsonSchema\Constraints;
1111

12-
use JsonSchema\Uri;
12+
use JsonSchema\Uri\UriRetriever;
1313

1414
/**
1515
* The Base Constraints, all Validators should extend this class
@@ -31,7 +31,7 @@ abstract class Constraint implements ConstraintInterface
3131
* @param int $checkMode
3232
* @param UriRetriever $uriRetriever
3333
*/
34-
public function __construct($checkMode = self::CHECK_MODE_NORMAL, \JsonSchema\Uri\UriRetriever $uriRetriever = null)
34+
public function __construct($checkMode = self::CHECK_MODE_NORMAL, UriRetriever $uriRetriever = null)
3535
{
3636
$this->checkMode = $checkMode;
3737
$this->uriRetriever = $uriRetriever;
@@ -40,11 +40,11 @@ public function __construct($checkMode = self::CHECK_MODE_NORMAL, \JsonSchema\Ur
4040
/**
4141
* @return UriRetriever $uriRetriever
4242
*/
43-
public function getUriRetriever()
43+
public function getUriRetriever()
4444
{
4545
if (is_null($this->uriRetriever))
4646
{
47-
$this->setUriRetriever(new \JsonSchema\Uri\UriRetriever);
47+
$this->setUriRetriever(new UriRetriever);
4848
}
4949

5050
return $this->uriRetriever;
@@ -53,7 +53,7 @@ public function getUriRetriever()
5353
/**
5454
* @param UriRetriever $uriRetriever
5555
*/
56-
public function setUriRetriever(\JsonSchema\Uri\UriRetriever $uriRetriever)
56+
public function setUriRetriever(UriRetriever $uriRetriever)
5757
{
5858
$this->uriRetriever = $uriRetriever;
5959
}
@@ -255,7 +255,7 @@ protected function checkFormat($value, $schema = null, $path = null, $i = null)
255255
protected function retrieveUri($uri)
256256
{
257257
if (null === $this->uriRetriever) {
258-
$this->setUriRetriever(new \JsonSchema\Uri\UriRetriever);
258+
$this->setUriRetriever(new UriRetriever);
259259
}
260260
$jsonSchema = $this->uriRetriever->retrieve($uri);
261261
// TODO validate using schema

src/JsonSchema/Constraints/Object.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ public function validateElement($element, $matches, $objectDefinition = null, $p
7575
$property = $this->getProperty($element, $i, new Undefined());
7676
$definition = $this->getProperty($objectDefinition, $i);
7777

78-
//required property
79-
if ($this->getProperty($definition, 'required') && $property instanceof Undefined) {
80-
$this->addError($path, "the property " . $i . " is required");
81-
}
82-
83-
//no additional properties allowed
78+
// no additional properties allowed
8479
if (!in_array($i, $matches) && $additionalProp === false && $this->inlineSchemaProperty !== $i && !$definition) {
8580
$this->addError($path, "The property " . $i . " is not defined and the definition does not allow additional properties");
8681
}
@@ -96,8 +91,10 @@ public function validateElement($element, $matches, $objectDefinition = null, $p
9691
$this->addError($path, "the presence of the property " . $i . " requires that " . $require . " also be present");
9792
}
9893

99-
//normal property verification
100-
$this->checkUndefined($value, $definition ? : new \stdClass(), $path, $i);
94+
if (!$definition) {
95+
// normal property verification
96+
$this->checkUndefined($value, new \stdClass(), $path, $i);
97+
}
10198
}
10299
}
103100

0 commit comments

Comments
 (0)