FormUserSettings::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Apps\Model\Admin\User;
4
5
use Ffcms\Core\Arch\Model;
6
7
/**
8
 * Class FormUserSettings. Settings of user app business logic model
9
 * @package Apps\Model\Admin\User
10
 */
11
class FormUserSettings extends Model
12
{
13
    public $registrationType;
14
    public $captchaOnLogin;
15
    public $captchaOnRegister;
16
17
    private $_config;
18
19
    /**
20
     * FormUserSettings constructor. Pass configs inside the model
21
     * @param array|null $config
22
     */
23
    public function __construct(array $config = null)
24
    {
25
        $this->_config = $config;
26
        parent::__construct();
27
    }
28
29
    /**
30
    * Load configs from app data
31
    */
32
    public function before()
33
    {
34
        if ($this->_config === null) {
35
            return;
36
        }
37
        foreach ($this->_config as $property => $value) {
38
            if (property_exists($this, $property)) {
39
                $this->$property = $value;
40
            }
41
        }
42
    }
43
44
    /**
45
     * Form display labels
46
     * @return array
47
     */
48
    public function labels(): array
49
    {
50
        return [
51
            'registrationType' => __('Registration type'),
52
            'captchaOnLogin' => __('Captcha on login'),
53
            'captchaOnRegister' => __('Captcha on registration')
54
        ];
55
    }
56
57
    /**
58
     * Validation rules
59
     * @return array
60
     */
61
    public function rules(): array
62
    {
63
        return [
64
            [['registrationType', 'captchaOnLogin'], 'required']
65
        ];
66
    }
67
}
68