Passed
Push — master ( fcf8a0...ba2801 )
by Mihail
04:49
created

FormSettings::labels()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Apps\Model\Admin\Newcontent;
4
5
use Ffcms\Core\Arch\Model;
6
use Apps\ActiveRecord\ContentCategory;
7
use Ffcms\Core\Helper\Serialize;
8
9
class FormSettings extends Model
10
{
11
    public $categories = array();
12
    public $count;
13
    public $cache = 300;
14
    
15
    private $_configs;
16
    
17
    /**
18
     * FormSettings constructor. Pass configs inside from controller
19
     * @param array $configs
20
     */
21
    public function __construct(array $configs)
22
    {
23
        $this->_configs = $configs;
24
        parent::__construct();
25
    }
26
27
    /**
28
    * Set default values from configs
29
    */
30
    public function before()
31
    {
32
        $this->categories = Serialize::decode($this->_configs['categories']);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Ffcms\Core\Helper\Seria..._configs['categories']) can also be of type string. However, the property $categories is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
33
        $this->count = (int)$this->_configs['count'];
34
        $this->cache = (int)$this->_configs['cache'];
35
    }
36
37
    /**
38
    * Labels for form
39
    */
40
    public function labels()
41
    {
42
        return [
43
            'categories' => __('Categories'),
44
            'count' => __('Count'),
45
            'cache' => __('Cache')
46
        ];
47
    }
48
49
    /**
50
    * Validation rules
51
    */
52
    public function rules()
53
    {
54
        return [
55
            [['count', 'categories'], 'required'],
56
            [['count', 'cache'], 'int']
57
        ];
58
    }
59
    
60
    /**
61
     * Get model output
62
     * @return array
63
     */
64
    public function getResult()
65
    {
66
        return [
67
            'count' => (int)$this->count,
68
            'cache' => (int)$this->cache,
69
            'categories' => Serialize::encode($this->categories)
70
        ];
71
    }
72
    
73
    public function getCategories()
74
    {
75
        return ContentCategory::getSortedCategories();
76
    }
77
}