Passed
Push — master ( 0456bd...25822b )
by Mihail
07:10
created

FormYandexToken::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Apps\Model\Admin\Main;
4
5
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\Model;
8
9
class FormYandexToken extends Model
10
{
11
    public $token;
12
    public $expires;
13
14
    public $_name = 'yaTokenForm';
15
16
    private $_cfg;
17
18
    /**
19
     * FormYandexToken constructor.
20
     * @param array $configs
21
     */
22
    public function __construct(array $configs)
23
    {
24
        $this->_cfg = $configs;
25
        parent::__construct(false);
26
    }
27
28
    /**
29
     * Display labels
30
     * @return array
31
     */
32
    public function labels(): array
33
    {
34
        return [
35
            'token' => 'Token',
36
            'expires' => 'Lifetime (secs)'
37
        ];
38
    }
39
40
    /**
41
     * Validation rules
42
     * @return array
43
     */
44
    public function rules(): array
45
    {
46
        return [
47
            [['token', 'expires'], 'required'],
48
            ['token', 'length_min', 20],
49
            ['expires', 'int']
50
        ];
51
    }
52
53
    /**
54
     * Save configs
55
     */
56
    public function make()
57
    {
58
        $cfg = $this->_cfg;
59
60
        $cfg['oauth']['token'] = $this->token;
61
        $cfg['oauth']['expires'] = time() + (int)$this->expires;
62
63
        App::$Properties->writeConfig('Yandex', $cfg);
64
    }
65
}