Completed
Pull Request — master (#1)
by Silvan
01:20
created

SlickWidget::init()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2.0005

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 18
cts 19
cp 0.9474
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 19
nc 2
nop 0
crap 2.0005
1
<?php
2
3
namespace dev7ch\slick;
4
5
use dev7ch\slick\assets\PicturefillAsset;
6
use dev7ch\slick\assets\ResourcesAsset;
7
use dev7ch\slick\assets\SlickAsset;
8
9 1
\Yii::setAlias('@slick', '@bower/slick-carousel');
10 1
\Yii::setAlias('@resources', dirname(__DIR__).'/src/resources');
11
12
class SlickWidget extends \luya\base\Widget
13
{
14
    public $baseUrl;
15
    public $images;
16
    public $slickConfig = [];
17
    public $slickConfigWidget;
18
19 1
    public function init()
20
    {
21 1
        PicturefillAsset::register($this->getView());
22 1
        SlickAsset::register($this->getView());
23 1
        ResourcesAsset::register($this->getView());
24
25 1
        if (Module::slickConfig() != false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison !== instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
26
            $this->slickConfig = Module::slickConfig();
0 ignored issues
show
Documentation Bug introduced by
It seems like \dev7ch\slick\Module::slickConfig() of type boolean is incompatible with the declared type array of property $slickConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
        } else {
28 1
            $this->slickConfig = $this->slickConfigWidget;
29
        }
30
31 1
        $this->view->registerJs(
32
            "var slickSlider = $('.slick-slider').slick({"
33 1
                .implode(', ',
34 1
                    array_map(
35 1
                        function ($config, $option) {
36 1
                            return sprintf('%s:%s', $option, $config);
37 1
                        },
38 1
                        $this->slickConfig, array_keys($this->slickConfig)
39
                    )
40
                ).
41 1
            '});',
42 1
            \luya\web\View::POS_READY,
43 1
            'slickSlider'
44
        );
45
46 1
        parent::init();
47 1
    }
48
49 1
    public function run()
50
    {
51 1
        return $this->render('SlickSlider', ['widget' => $this]);
52
    }
53
}
54