Completed
Push — master ( e9cf88...ab22e5 )
by Klochok
10:21 queued 06:45
created

OrderPositionDescriptionWidget   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
eloc 36
c 2
b 0
f 1
dl 0
loc 59
ccs 0
cts 40
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A formatConfig() 0 11 3
A init() 0 29 1
A run() 0 3 1
1
<?php
2
/**
3
 * Server module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\widgets\cart;
12
13
use hipanel\modules\server\cart\ServerOrderDedicatedProduct;
14
use hipanel\modules\server\cart\ServerOrderProduct;
15
use yii\base\Widget;
16
use yii\helpers\Html;
17
18
/**
19
 * Class OrderPositionDescriptionWidget renders description for Server order position
20
 * in cart.
21
 */
22
class OrderPositionDescriptionWidget extends Widget
23
{
24
    /**
25
     * @var ServerOrderProduct|ServerOrderDedicatedProduct
26
     */
27
    public $position;
28
29
    public function init()
30
    {
31
        $this->view->registerCss(<<<CSS
32
            .cart-item .dl-config { display: none; }
33
            
34
            dl.dl-config {
35
                padding: 1em 0 0;
36
                display: flex;
37
                flex-flow: row wrap;
38
            }
39
40
            dl.dl-config dt {
41
                flex-basis: 16%;
42
                text-align: left;
43
                width: auto;
44
            }
45
46
            dl.dl-config dt::after {
47
                content: ":";
48
            }
49
50
            dl.dl-config dd {
51
                flex-basis: 70%;
52
                flex-grow: 1;
53
                margin: 0;
54
                padding: 0;
55
            }
56
CSS
57
        , [], __CLASS__ . '_client_css');
58
    }
59
60
    /** {@inheritdoc} */
61
    public function run()
62
    {
63
        return $this->render('_orderPositionDescription', ['position' => $this->position]);
64
    }
65
66
    /**
67
     * @param array $items
68
     * @return string
69
     */
70
    public function formatConfig(array $items = []): string
71
    {
72
        $html = '';
73
        foreach ($items as $label => $value) {
74
            if (empty($value)) {
75
                continue;
76
            }
77
            $html .= Html::tag('dt', $label) . Html::tag('dd', $value);
78
        }
79
80
        return Html::tag('dl', $html, ['class' => 'dl-horizontal dl-config']);
81
    }
82
}
83