Skip to content
Permalink
Browse files

Fix return type of error()

Make it consistent (always an array). Also make the two implementations
agree on a return type.
  • Loading branch information...
markstory committed Feb 3, 2014
1 parent d7d94e7 commit 86c0fa0212cb1f9ee80a568009189c399801dc8c
@@ -154,12 +154,12 @@ public function hasError($field) {
* Get the errors for a given field
*
* @param string $field A dot separated path to check errors on.
* @return mixed Either a string or an array of errors. Null
* will be returned when the field path is undefined.
* @return array An array of errors, an empty array will be returned when the
* context has no errors.
*/
public function error($field) {
if (empty($this->_context['errors'])) {
return null;
return [];
}
return Hash::get($this->_context['errors'], $field);
}
@@ -301,19 +301,17 @@ public function hasError($field) {
return !empty($errors);
}
/**
* Get the errors for a given field
*
* @param string $field A dot separated path to check errors on.
* @return array|null Either an array of errors. Null will be returned when the
* field path is undefined or there is no error.
* @return array An array of errors.
*/
public function error($field) {
$parts = explode('.', $field);
list($entity, $prop) = $this->_getEntity($parts);
if (!$entity) {
return false;
return [];
}
return $entity->errors(array_pop($parts));
}
@@ -153,6 +153,9 @@ public function testAttributes() {
* @return void
*/
public function testError() {
$context = new ArrayContext($this->request, []);
$this->assertEquals([], $context->error('Comments.empty'));
$context = new ArrayContext($this->request, [
'errors' => [
'Comments' => [

0 comments on commit 86c0fa0

Please sign in to comment.
You can’t perform that action at this time.