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

FormYandexCounter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 6 1
A getCounters() 0 3 1
A __construct() 0 4 1
A rules() 0 5 1
1
<?php
2
3
namespace Apps\Model\Admin\Main;
4
5
6
use Ffcms\Core\App;
7
use Ffcms\Core\Arch\Model;
8
9
/**
10
 * Class FormYandexCounter
11
 * @package Apps\Model\Admin\Main
12
 */
13
class FormYandexCounter extends Model
14
{
15
    public $counter;
16
17
    private $_counters;
18
19
    /**
20
     * FormYandexCounter constructor.
21
     * @param array $counters
22
     */
23
    public function __construct(array $counters)
24
    {
25
        $this->_counters = $counters;
26
        parent::__construct(false);
27
    }
28
29
    /**
30
     * Validation rules
31
     * @return array
32
     */
33
    public function rules(): array
34
    {
35
        return [
36
            ['counter', 'required'],
37
            ['counter', 'int']
38
        ];
39
    }
40
41
    /**
42
     * Save counter id to configuration file
43
     */
44
    public function make()
45
    {
46
        $cfg = App::$Properties->getAll('Yandex');
47
        $cfg['metrika']['id'] = (int)$this->counter;
48
49
        App::$Properties->writeConfig('Yandex', $cfg);
0 ignored issues
show
Bug introduced by zenn
It seems like $cfg can also be of type null; however, parameter $data of Ffcms\Core\Properties::writeConfig() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

49
        App::$Properties->writeConfig('Yandex', /** @scrutinizer ignore-type */ $cfg);
Loading history...
50
    }
51
52
    /**
53
     * Get counter id->name
54
     * @return array
55
     */
56
    public function getCounters(): array
57
    {
58
        return $this->_counters;
59
    }
60
}