Module   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 21
dl 0
loc 70
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 1
A registerTranslations() 0 7 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: floor12
5
 * Date: 31.12.2017
6
 * Time: 14:45
7
 */
8
9
namespace floor12\files;
10
11
use Yii;
12
use yii\db\Connection;
13
14
/**
15
 * Class Module
16
 * @package floor12\files
17
 * @property string $token_salt
18
 * @property string $storage
19
 * @property string $controllerNamespace
20
 *
21
 */
22
class Module extends \yii\base\Module
23
{
24
    /**
25
     * @inheritdoc
26
     */
27
    public $controllerNamespace = 'floor12\files\controllers';
28
29
    /** Путь к файловому хранилищу
30
     * @var string
31
     */
32
    public $storage = '@vendor/../storage';
33
34
    /** Путь к  хранилищу кешей
35
     * @var string
36
     */
37
    public $cache = '@vendor/../storage_cache';
38
    /**
39
     * @var string
40
     */
41
    public $hostStatic = '';
42
    /**
43
     * @var string
44
     */
45
    public $ffmpeg = '/usr/bin/ffmpeg';
46
    /**
47
     * @var string
48
     */
49
    public $token_salt = 'randomString412DDs@#KJH';
50
    /**
51
     * @var string
52
     */
53
    public $storageFullPath;
54
    /**
55
     * @var string
56
     */
57
    public $cacheFullPath;
58
    /**
59
     * @var bool
60
     */
61
    public $allowOfficePreview = true;
62
    /**
63
     * @var array
64
     */
65
    public $params = ['db' => 'db'];
66
    /**
67
     * @var Connection
68
     */
69
    public $db;
70
71
    /**
72
     * @inheritdoc
73
     */
74
    public function init()
75
    {
76
        $this->registerTranslations();
77
        $this->db = Yii::$app->{$this->params['db']};
78
        $this->storageFullPath = Yii::getAlias($this->storage);
0 ignored issues
show
Documentation Bug introduced by
It seems like Yii::getAlias($this->storage) can also be of type false. However, the property $storageFullPath is declared as type string. 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...
79
        $this->cacheFullPath = Yii::getAlias($this->cache);
0 ignored issues
show
Documentation Bug introduced by
It seems like Yii::getAlias($this->cache) can also be of type false. However, the property $cacheFullPath is declared as type string. 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...
80
    }
81
82
    /**
83
     * @return void
84
     */
85
    public function registerTranslations()
86
    {
87
        $i18n = Yii::$app->i18n;
88
        $i18n->translations['files'] = [
89
            'class' => 'yii\i18n\PhpMessageSource',
90
            'sourceLanguage' => 'en-US',
91
            'basePath' => '@vendor/floor12/yii2-module-files/src/messages',
92
        ];
93
    }
94
95
}