-
Notifications
You must be signed in to change notification settings - Fork 363
Added optional args to addError #141
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
Changes from 4 commits
1ed067c
461d2eb
8bb67ec
b432b25
41cf91f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,13 +29,13 @@ public function check($element, $schema = null, $path = null, $i = null) | |
| switch ($schema->format) { | ||
| case 'date': | ||
| if (!$date = $this->validateDateTime($element, 'Y-m-d')) { | ||
| $this->addError($path, sprintf('Invalid date %s, expected format YYYY-MM-DD', json_encode($element))); | ||
| $this->addError($path, sprintf('Invalid date %s, expected format YYYY-MM-DD', json_encode($element)), 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'time': | ||
| if (!$this->validateDateTime($element, 'H:i:s')) { | ||
| $this->addError($path, sprintf('Invalid time %s, expected format hh:mm:ss', json_encode($element))); | ||
| $this->addError($path, sprintf('Invalid time %s, expected format hh:mm:ss', json_encode($element)), 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
|
|
@@ -45,74 +45,74 @@ public function check($element, $schema = null, $path = null, $i = null) | |
| !$this->validateDateTime($element, 'Y-m-d\TH:i:sP') && | ||
| !$this->validateDateTime($element, 'Y-m-d\TH:i:sO') | ||
| ) { | ||
| $this->addError($path, sprintf('Invalid date-time %s, expected format YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss+hh:mm', json_encode($element))); | ||
| $this->addError($path, sprintf('Invalid date-time %s, expected format YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DDThh:mm:ss+hh:mm', json_encode($element)), 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'utc-millisec': | ||
| if (!$this->validateDateTime($element, 'U')) { | ||
| $this->addError($path, sprintf('Invalid time %s, expected integer of milliseconds since Epoch', json_encode($element))); | ||
| $this->addError($path, sprintf('Invalid time %s, expected integer of milliseconds since Epoch', json_encode($element)), 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'regex': | ||
| if (!$this->validateRegex($element)) { | ||
| $this->addError($path, 'Invalid regex format ' . $element); | ||
| $this->addError($path, 'Invalid regex format ' . $element, 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'color': | ||
| if (!$this->validateColor($element)) { | ||
| $this->addError($path, "Invalid color"); | ||
| $this->addError($path, "Invalid color", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'style': | ||
| if (!$this->validateStyle($element)) { | ||
| $this->addError($path, "Invalid style"); | ||
| $this->addError($path, "Invalid style", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'phone': | ||
| if (!$this->validatePhone($element)) { | ||
| $this->addError($path, "Invalid phone number"); | ||
| $this->addError($path, "Invalid phone number", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'uri': | ||
| if (null === filter_var($element, FILTER_VALIDATE_URL, FILTER_NULL_ON_FAILURE)) { | ||
| $this->addError($path, "Invalid URL format"); | ||
| $this->addError($path, "Invalid URL format", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'email': | ||
| if (null === filter_var($element, FILTER_VALIDATE_EMAIL, FILTER_NULL_ON_FAILURE)) { | ||
| $this->addError($path, "Invalid email"); | ||
| $this->addError($path, "Invalid email", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'ip-address': | ||
| case 'ipv4': | ||
| if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4)) { | ||
| $this->addError($path, "Invalid IP address"); | ||
| $this->addError($path, "Invalid IP address", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'ipv6': | ||
| if (null === filter_var($element, FILTER_VALIDATE_IP, FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV6)) { | ||
| $this->addError($path, "Invalid IP address"); | ||
| $this->addError($path, "Invalid IP address", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| case 'host-name': | ||
| case 'hostname': | ||
| if (!$this->validateHostname($element)) { | ||
| $this->addError($path, "Invalid hostname"); | ||
| $this->addError($path, "Invalid hostname", 'format', array('format' => $schema->format,)); | ||
| } | ||
| break; | ||
|
|
||
| default: | ||
| $this->addError($path, "Unknown format: " . json_encode($schema->format)); | ||
| $this->addError($path, "Unknown format: " . json_encode($schema->format), 'format', array('format' => $schema->format,)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following #125 discussion the default case should be empty
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Maks3w , you mean there should not be "$this->addError ..." under "default:" ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes the whole line must be eliminated. default must be empty
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for clarify. This is not a bug in your PR. The bug already exists in the upstream code, the reason of modify the line is to prevent (supersede) a git conflict with #125 |
||
| break; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typehinting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's in ConstraintInterface.php the phpdoc here is just inheriting the interface class.