PrepaidAmountWidget::renderTextInput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 13
cp 0
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\widgets;
12
13
use hipanel\inputs\OptionsInput;
14
use hipanel\modules\finance\models\ServerResource;
15
use yii\base\Widget;
16
use yii\helpers\Html;
17
use yii\widgets\ActiveField;
18
19
final class PrepaidAmountWidget extends Widget
20
{
21
    public $model;
22
    public $attribute;
23
24
    /**
25
     * @var ActiveField
26
     */
27
    public $activeField;
28
29
    /** @var ServerResource */
30
    public $resource;
31
32
    public function init()
33
    {
34
        Html::addCssClass($this->activeField->options, 'form-group-sm');
35
    }
36
37
    public function run()
38
    {
39
        $type = $this->resource->decorator()->prepaidAmountType();
40
41
        if ($type instanceof OptionsInput) {
42
            echo $this->renderDropdownInput($type);
43
        } else {
44
            echo $this->renderTextInput($type);
45
        }
46
    }
47
48
    private function renderTextInput($type)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        $this->activeField->template = "{label}\n<div class=\"input-group\">{input}</div>\n{hint}\n{error}";
51
52
        return $this->activeField->input('number', [
53
            'class' => 'form-control price-input',
54
            'autocomplete' => false,
55
            'step' => 'any',
56
            'data' => [
57
                'min-price' => $this->resource->getMinimumQuantity(),
58
            ],
59
            'value' => $this->resource->decorator()->getPrepaidQuantity(),
60
        ]);
61
    }
62
63
    private function renderDropdownInput(OptionsInput $boolean)
64
    {
65
        return $this->activeField->dropDownList($boolean->getOptions(), [
66
            'class' => 'form-control',
67
            'value' => $this->resource->decorator()->getPrepaidQuantity(),
68
        ]);
69
    }
70
}
71