FormSettings   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 28
dl 0
loc 66
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A before() 0 9 4
A rules() 0 6 1
A labels() 0 10 1
1
<?php
2
3
namespace Apps\Model\Admin\Comments;
4
5
use Ffcms\Core\Arch\Model;
6
7
/**
8
 * Class FormSettings. Model for settings of comments application
9
 * @package Apps\Model\Admin\Comments
10
 */
11
class FormSettings extends Model
12
{
13
    public $perPage;
14
    public $delay;
15
    public $minLength;
16
    public $maxLength;
17
    public $guestAdd;
18
    public $guestModerate;
19
    public $onlyLocale;
20
21
    /** @var array|null */
22
    private $_configs;
23
24
    /**
25
     * FormSettings constructor. Pass array configs from controller.
26
     * @param array|null $configs
27
     */
28
    public function __construct(array $configs = null)
29
    {
30
        $this->_configs = $configs;
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Set model properties based on defaults config values
36
     */
37
    public function before()
38
    {
39
        if ($this->_configs === null) {
40
            return;
41
        }
42
43
        foreach ($this->_configs as $property => $value) {
44
            if (property_exists($this, $property)) {
45
                $this->{$property} = $value;
46
            }
47
        }
48
    }
49
50
    /**
51
     * Labels for form
52
     * @return array
53
     */
54
    public function labels(): array
55
    {
56
        return [
57
            'perPage' => __('Comments count'),
58
            'delay' => __('Delay'),
59
            'minLength' => __('Minimal length'),
60
            'maxLength' => __('Maximum length'),
61
            'guestAdd' => __('Guest add'),
62
            'guestModerate' => __('Guest moderate'),
63
            'onlyLocale' => __('Only locale')
64
        ];
65
    }
66
67
    /**
68
     * Validation rules for comments settings
69
     * @return array
70
     */
71
    public function rules(): array
72
    {
73
        return [
74
            [['perPage', 'delay', 'minLength', 'maxLength', 'guestAdd', 'guestModerate', 'onlyLocale'], 'required'],
75
            [['minLength', 'maxLength', 'delay', 'perPage', 'onlyLocale'], 'int'],
76
            [['guestAdd', 'onlyLocale', 'guestModerate'], 'boolean']
77
        ];
78
    }
79
}
80