AppAsset::init()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 3
eloc 9
nc 3
nop 0
1
<?php
2
3
namespace app\assets;
4
5
/**
6
 * @link http://www.yiiframework.com/
7
 *
8
 * @copyright Copyright (c) 2008 Yii Software LLC
9
 * @license http://www.yiiframework.com/license/
10
 */
11
12
use yii\helpers\FileHelper;
13
use yii\web\AssetBundle;
14
15
/**
16
 * Configuration for `backend` client script files.
17
 *
18
 * @since 4.0
19
 */
20
class AppAsset extends AssetBundle
21
{
22
    public $sourcePath = __DIR__.'/web';
23
24
    public $css = [
25
        // Note: less files require a compiler (available by default on Phundament Docker images)
26
        // use .css alternatively
27
        #'less/app.less',
28
    ];
29
30
    public $js = [
31
        'js/app.js',
32
    ];
33
34
    // we recompile the less files from 'yii\bootstrap\BootstrapAsset' and include the css in app.css
35
    // therefore we set bundle to false in application config
36
    public $depends = [
37
        'yii\bootstrap\BootstrapAsset',
38
        'yii\web\YiiAsset',
39
    ];
40
41
    public function init()
42
    {
43
        parent::init();
44
45
        // /!\ CSS/LESS development only setting /!\
46
        // Touch the asset folder with the highest mtime of all contained files
47
        // This will create a new folder in web/assets for every change and request
48
        // made to the app assets.
49
        if (getenv('APP_ASSET_FORCE_PUBLISH')) {
50
            $path = \Yii::getAlias($this->sourcePath);
51
            $files = FileHelper::findFiles($path);
0 ignored issues
show
Bug introduced by
It seems like $path defined by \Yii::getAlias($this->sourcePath) on line 50 can also be of type boolean; however, yii\helpers\BaseFileHelper::findFiles() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
52
            $mtimes = [];
53
            foreach ($files as $file) {
54
                $mtimes[] = filemtime($file);
55
            }
56
            touch($path, max($mtimes));
57
        }
58
    }
59
}
60