Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion src/JsonSchema/ConstraintError.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function getMessage()
self::NOT => 'Matched a schema which it should not',
self::ONE_OF => 'Failed to match exactly one schema',
self::REQUIRED => 'The property %s is required',
self::REQUIRED_D3 => 'Is missing and it is required',
self::REQUIRED_D3 => 'The property %s is required',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is redundant - there's already an identical message template on line 95 (REQUIRED), so IMO it makes more sense to just use that.

self::REQUIRES => 'The presence of the property %s requires that %s also be present',
self::PATTERN => 'Does not match the regex pattern %s',
self::PREGEX_INVALID => 'The pattern %s is invalid',
Expand Down
3 changes: 2 additions & 1 deletion src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ protected function validateCommonProperties(&$value, $schema = null, JsonPointer
} elseif (isset($schema->required) && !is_array($schema->required)) {
// Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true}
if ($schema->required && $value instanceof self) {
$this->addError(ConstraintError::REQUIRED_D3(), $path);
$propertyName = current($path->getPropertyPaths());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use end() rather than current() - current() makes assumptions about the state of the internal pointer on the returned array, which could result in hard-to-find bugs if the pointer code is changed at a later date.

$this->addError(ConstraintError::REQUIRED_D3(), $path, array('property' => $propertyName));
}
}
}
Expand Down