Passed
Push — master ( 004834...f22cf7 )
by Mihail
04:58
created

FormSettings::before()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Apps\Model\Admin\Newcomment;
4
5
use Ffcms\Core\Arch\Model;
6
7
class FormSettings extends Model
8
{
9
    public $count;
10
    public $snippet;
11
    public $cache;
12
    
13
    private $_configs;
14
    
15
    /**
16
     * FormSettings constructor. Pass configs inside from controller
17
     * @param array $configs
18
     */
19
    public function __construct(array $configs)
20
    {
21
        $this->_configs = $configs;
22
        parent::__construct();
23
    }
24
25
    /**
26
    * Set default values from configs
27
    */
28
    public function before()
29
    {
30
        $this->snippet = (int)$this->_configs['snippet'];
31
        $this->count = (int)$this->_configs['count'];
32
        $this->cache = (int)$this->_configs['cache'];
33
    }
34
35
    /**
36
    * Labels for form display
37
    */
38
    public function labels()
39
    {
40
        return [
41
            'snippet' => __('Max length'),
42
            'count' => __('Comments count'),
43
            'cache' => __('Cache')
44
        ];
45
    }
46
47
    /**
48
    * Settings validation rules
49
    */
50 View Code Duplication
    public function rules()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        return [
53
            [['snippet', 'count', 'cache'], 'required'],
54
            [['snippet', 'count', 'cache'], 'int']
55
        ];
56
    }
57
}