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

FormulaInput   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 4
dl 0
loc 43
c 0
b 0
f 0
ccs 0
cts 20
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A registerClientScript() 0 6 1
A run() 0 6 1
A registerHelpModal() 0 5 1
A formulaLinesCount() 0 4 1
A getHelpModalSelector() 0 4 1
1
<?php
2
3
namespace hipanel\modules\finance\widgets;
4
5
use hipanel\modules\finance\models\Price;
6
use hiqdev\assets\autosize\AutosizeAsset;
7
use Yii;
8
use yii\helpers\BaseHtml;
9
use yii\web\NotAcceptableHttpException;
10
use yii\web\View;
11
use yii\widgets\InputWidget;
12
13
/**
14
 * Class FormulaInput
15
 *
16
 * @author Dmytro Naumenko <[email protected]>
17
 */
18
class FormulaInput extends InputWidget
19
{
20
    /** @var Price */
21
    public $model;
22
23
    /**
24
     * @var string
25
     */
26
    private $helpModalSelector;
27
28
    public function registerClientScript()
29
    {
30
        $this->registerHelpModal();
31
        AutosizeAsset::register($this->view);
32
        $this->view->registerJs("autosize($('.formula-input'));");
33
    }
34
35
    public function run()
36
    {
37
        $this->registerClientScript();
38
39
        return $this->render('formulaInput');
40
    }
41
42
    private function registerHelpModal(): void
43
    {
44
        $help = Yii::createObject(FormulaHelpModal::class);
45
        $this->helpModalSelector = '#' . $help->run();
46
    }
47
48
    public function formulaLinesCount()
49
    {
50
        return count($this->model->formulaLines());
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getHelpModalSelector(): string
57
    {
58
        return $this->helpModalSelector;
59
    }
60
}
61