Passed
Push — master ( 79bb6c...ad8dc9 )
by Alexey
03:10
created

Module   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 2
b 0
f 0
dl 0
loc 51
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 10 2
A behaviors() 0 5 1
A translate() 0 3 1
1
<?php
2
3
namespace modules\main;
4
5
use Yii;
6
use yii\filters\RateLimiter;
7
8
/**
9
 * Class Module
10
 * @package modules\main
11
 */
12
class Module extends \yii\base\Module
13
{
14
    /**
15
     * @inheritdoc
16
     * @return array
17
     */
18
    public function behaviors()
19
    {
20
        return [
21
            'rateLimiter' => [
22
                'class' => RateLimiter::class
23
            ]
24
        ];
25
    }
26
27
    /**
28
     * @var string
29
     */
30
    public $controllerNamespace = 'modules\main\controllers\frontend';
31
32
    /**
33
     * @var bool Если модуль используется для админ-панели.
34
     */
35
    public $isBackend;
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function init()
41
    {
42
        parent::init();
43
44
        // Это здесь для того, чтобы переключаться между frontend и backend
45
        if ($this->isBackend === true) {
46
            $this->controllerNamespace = 'modules\main\controllers\backend';
47
            $this->setViewPath('@modules/main/views/backend');
48
        } else {
49
            $this->setViewPath('@modules/main/views/frontend');
50
        }
51
    }
52
53
    /**
54
     * @param string $category
55
     * @param string $message
56
     * @param array $params
57
     * @param null|string $language
58
     * @return string
59
     */
60
    public static function translate($category, $message, $params = [], $language = null)
61
    {
62
        return Yii::t('modules/main/' . $category, $message, $params, $language);
63
    }
64
}
65