Test Failed
Push — master ( e3c39f...fe570d )
by Mihail
07:20
created

FormSettings   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 17
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A rules() 0 5 1
A labels() 0 5 1
A before() 0 8 4
1
<?php
2
3
namespace Apps\Model\Admin\Search;
4
5
use Ffcms\Core\Arch\Model;
6
7
/**
8
 * Class FormSettings. Model to transfer and validate input data & attributes for search admin configs.
9
 * @package Apps\Model\Admin\Search
10
 */
11
class FormSettings extends Model
12
{
13
    public $itemPerApp;
14
    public $minLength;
15
16
    private $_configs;
17
18
    /**
19
     * ForumSettings constructor. Construct model with default values
20
     * @param array|null $configs
21
     */
22
    public function __construct(array $configs = null)
23
    {
24
        $this->_configs = $configs;
25
        parent::__construct();
26
    }
27
28
    public function before()
29
    {
30
        if ($this->_configs === null) {
31
            return;
32
        }
33
        foreach ($this->_configs as $property => $value) {
34
            if (property_exists($this, $property)) {
35
                $this->$property = $value;
36
            }
37
        }
38
    }
39
40
    /**
41
     * Labels for admin settings form
42
     * @return array
43
     */
44
    public function labels(): array
45
    {
46
        return [
47
            'itemPerApp' => __('Search count'),
48
            'minLength' => __('Min length')
49
        ];
50
    }
51
52
    /**
53
     * Validation rules
54
     * @return @array
0 ignored issues
show
Documentation Bug introduced by
The doc comment @array at position 0 could not be parsed: Unknown type name '@array' at position 0 in @array.
Loading history...
55
     */
56
    public function rules(): array
57
    {
58
        return [
59
            [['itemPerApp', 'minLength'], 'required'],
60
            [['itemPerApp', 'minLength'], 'int']
61
        ];
62
    }
63
}
64