Completed
Push — master ( 243dc1...429fcc )
by Dmitry
14:10
created

LimitValidator::validateAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace hiapi\validators;
4
5
use yii\validators\Validator;
6
7
/**
8
 * Validates a a value to be used as a LIMIT
9
 *
10
 * @author Dmytro Naumenko <[email protected]>
11
 */
12
class LimitValidator extends Validator
13
{
14
    public function __construct(array $config = [])
15
    {
16
        parent::__construct($config);
17
18
        $this->message = 'The limit is not valid';
19
    }
20
21
    public function validateAttribute($model, $attribute)
22
    {
23
        $model->$attribute = mb_strtolower($model->$attribute);
24
25
        parent::validateAttribute($model, $attribute);
26
    }
27
28
    protected function validateValue($value)
29
    {
30
        if (empty($value) || $value === 'all') {
31
            return null;
32
        }
33
34
        if (is_numeric($value)) {
35
            return null;
36
        }
37
38
        return [$this->message, null];
39
    }
40
}
41