Remove some code duplication (validation rules)
This commit is contained in:
@@ -155,13 +155,12 @@ class Comment extends Base
|
||||
*/
|
||||
public function validateCreation(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
new Validators\Required('task_id', t('This value is required')),
|
||||
new Validators\Integer('task_id', t('This value must be an integer')),
|
||||
$rules = array(
|
||||
new Validators\Required('user_id', t('This value is required')),
|
||||
new Validators\Integer('user_id', t('This value must be an integer')),
|
||||
new Validators\Required('comment', t('Comment is required'))
|
||||
));
|
||||
new Validators\Required('task_id', t('This value is required')),
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
@@ -178,15 +177,31 @@ class Comment extends Base
|
||||
*/
|
||||
public function validateModification(array $values)
|
||||
{
|
||||
$v = new Validator($values, array(
|
||||
$rules = array(
|
||||
new Validators\Required('id', t('This value is required')),
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
new Validators\Required('comment', t('Comment is required'))
|
||||
));
|
||||
);
|
||||
|
||||
$v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
|
||||
|
||||
return array(
|
||||
$v->execute(),
|
||||
$v->getErrors()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Common validation rules
|
||||
*
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
private function commonValidationRules()
|
||||
{
|
||||
return array(
|
||||
new Validators\Integer('id', t('This value must be an integer')),
|
||||
new Validators\Integer('task_id', t('This value must be an integer')),
|
||||
new Validators\Integer('user_id', t('This value must be an integer')),
|
||||
new Validators\Required('comment', t('Comment is required'))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user