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

LimitValidator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validateAttribute() 0 6 1
A validateValue() 0 12 4
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