Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 86c0fa0212cb1f9ee80a568009189c399801dc8c 1 parent d7d94e7
@markstory markstory authored
View
6 src/View/Form/ArrayContext.php
@@ -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);
}
View
6 src/View/Form/EntityContext.php
@@ -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));
}
View
3  tests/TestCase/View/Form/ArrayContextTest.php
@@ -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' => [
Please sign in to comment.
Something went wrong with that request. Please try again.