Completed
Pull Request — master (#22)
by
unknown
01:34
created

QueryBuilderAsset   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 47
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isBs4() 0 7 2
A init() 0 11 2
1
<?php
2
3
namespace leandrogehlen\querybuilder;
4
5
use Yii;
6
use yii\helpers\StringHelper;
7
use yii\web\AssetBundle;
8
9
/**
10
 * This asset bundle provides the [jquery QueryBuilder library](https://github.com/mistic100/jQuery-QueryBuilder)
11
 *
12
 * @author Leandro Gehlen <[email protected]>
13
 */
14
class QueryBuilderAsset extends AssetBundle {
15
16
    public $sourcePath = '@bower/jquery-querybuilder/dist';
17
18
    public $js = [
19
        'js/query-builder.standalone.min.js',
20
    ];
21
22
    public $css = [
23
        'css/query-builder.default.min.css',
24
    ];
25
26
    public $depends = [
27
        'yii\web\JqueryAsset',
28
        'leandrogehlen\querybuilder\BootstrapAsset',
29
    ];
30
31
    /**
32
     * check wether this app has bsVersion and use bs4 as default bsVersion
33
     * because many yii2 user use kartik-v ekstension, we follow his conventions in set the bsVersion
34
     * 
35
     * @return bool
36
     * @author @hoaah ([email protected])
37
     */
38
    public function isBs4()
39
    {
40
        if(isset(Yii::$app->params['bsVersion'])){
41
            return (StringHelper::startsWith(Yii::$app->params['bsVersion'], '4'));
42
        }
43
        return false;
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    public function init()
50
    {
51
        if ($this->isBs4()) {
52
            $this->depends = [
53
                'yii\web\JqueryAsset',
54
                'yii\bootstrap4\BootstrapAsset'
55
            ];
56
        }
57
58
        parent::init();
59
    }
60
} 
61