Completed
Push — master ( bef74a...88d31d )
by Tobias
10:04 queued 07:36
created

AppAsset::init()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
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 = '@app/assets/web';
23
24
    public $js = [
25
        'js/app.js',
26
    ];
27
28
    public $css = [
29
        // Note: less files require a compiler (available by default on Phundament Docker images)
30
        // use .css alternatively
31
        #'less/app.less',
32
    ];
33
34
    public $depends = [
35
        'yii\web\YiiAsset',
36
        'yii\bootstrap\BootstrapPluginAsset',
37
        // if we recompile the less files from 'yii\bootstrap\BootstrapAsset' and include the css in app.css
38
        // we need set bundle to `false` in application config and remove the following line
39
        'yii\bootstrap\BootstrapAsset',
40
    ];
41
42
    public function init()
43
    {
44
        parent::init();
45
46
        // /!\ CSS/LESS development only setting /!\
47
        // Touch the asset folder with the highest mtime of all contained files
48
        // This will create a new folder in web/assets for every change and request
49
        // made to the app assets.
50
        if (getenv('APP_ASSET_FORCE_PUBLISH')) {
51
            $path = \Yii::getAlias($this->sourcePath);
52
            $files = FileHelper::findFiles($path);
0 ignored issues
show
Bug introduced by
It seems like $path defined by \Yii::getAlias($this->sourcePath) on line 51 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...
53
            $mtimes = [];
54
            foreach ($files as $file) {
55
                $mtimes[] = filemtime($file);
56
            }
57
            touch($path, max($mtimes));
58
        }
59
    }
60
}
61