Completed
Push — master ( ef2c0c...0622f1 )
by Dmitry
17:35
created

PrepaidAmountWidget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 50
ccs 0
cts 31
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A run() 0 10 2
A renderTextInput() 0 12 1
A renderDropdownInput() 0 7 1
1
<?php
2
3
namespace hipanel\modules\finance\widgets;
4
5
use hipanel\inputs\BooleanInput;
6
use hipanel\modules\finance\models\ServerResource;
7
use yii\base\Widget;
8
use yii\helpers\Html;
9
use yii\widgets\ActiveField;
10
11
final class PrepaidAmountWidget extends Widget
12
{
13
    public $model;
14
    public $attribute;
15
16
    /**
17
     * @var ActiveField
18
     */
19
    public $activeField;
20
21
    /** @var ServerResource */
22
    public $resource;
23
24
    public function init()
25
    {
26
        Html::addCssClass($this->activeField->options, 'form-group-sm');
27
    }
28
29
    public function run()
30
    {
31
        $type = $this->resource->decorator()->prepaidAmountType();
32
33
        if ($type instanceof BooleanInput) {
0 ignored issues
show
Bug introduced by
The class hipanel\inputs\BooleanInput does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
34
            echo $this->renderDropdownInput($type);
35
        } else {
36
            echo $this->renderTextInput($type);
37
        }
38
    }
39
40
    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...
41
    {
42
        $this->activeField->template = "{label}\n<div class=\"input-group\">{input}<span class=\"input-group-addon\">{unit}</span></div>\n{hint}\n{error}";
43
        $this->activeField->parts = ['{unit}' => $this->resource->decorator()->displayUnit()];
44
45
        return $this->activeField->input('number', [
46
            'class' => 'form-control price-input',
47
            'autocomplete' => false,
48
            'step' => 'any',
49
            'value' => $this->resource->decorator()->getPrepaidQuantity(),
50
        ]);
51
    }
52
53
    private function renderDropdownInput(BooleanInput $boolean)
54
    {
55
        return $this->activeField->dropDownList($boolean->getOptions(), [
56
            'class' => 'form-control',
57
            'value' => $this->resource->decorator()->getPrepaidQuantity(),
58
        ]);
59
    }
60
}
61