Completed
Push — master ( 4f1415...383c20 )
by Dmitry
05:05
created

FormulaHelpModal::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 7
nc 2
nop 0
crap 6
1
<?php
2
3
namespace hipanel\modules\finance\widgets;
4
5
use hipanel\modules\finance\providers\FormulaExamplesProvider;
6
use nezhelskoy\highlight\HighlightAsset;
7
use yii\base\Widget;
8
use yii\web\View;
9
10
/**
11
 * Class FormulaHelpModal
12
 *
13
 * @author Dmytro Naumenko <[email protected]>
14
 */
15
class FormulaHelpModal extends Widget
16
{
17
    /**
18
     * @var bool
19
     */
20
    private $wasRendered = false;
21
22
    public function run()
23
    {
24
        if (!$this->wasRendered) {
25
            $this->registerClientScript();
26
            $this->view->on(View::EVENT_END_BODY, function () {
27
                echo $this->render('formulaHelpModal');
28
            });
29
            $this->wasRendered = true;
30
        }
31
32
        return $this->getId();
33
    }
34
35
    public function formulaExamplesProvider(): FormulaExamplesProvider
36
    {
37
        return new FormulaExamplesProvider();
38
    }
39
40
    private function registerClientScript()
41
    {
42
        HighlightAsset::register($this->view);
43
    }
44
}
45