Passed
Push — master ( 74b07d...18673c )
by Dmitrijs
01:49
created

Card   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 26
dl 0
loc 74
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 1
A init() 0 21 2
1
<?php
2
/**
3
 * @link https://github.com/DMGPage/yii2-materialize
4
 * @copyright Copyright (c) 2018 Dmitrijs Reinmanis
5
 * @license https://github.com/DMGPage/yii2-materialize/blob/master/LICENSE
6
 */
7
8
namespace dmgpage\yii2materialize\widgets;
9
10
use yii\base\Widget as BaseWidget;
11
use dmgpage\yii2materialize\helpers\Html;
12
13
/**
14
 * Cards are a convenient means of displaying content composed of different types of objects.
15
 * They’re also well-suited for presenting similar objects whose size or supported actions can vary considerably,
16
 * like photos with captions of variable length.
17
 * 
18
 */
19
class Card extends BaseWidget
20
{
21
    /**
22
     * @var array the HTML attributes for the row container tag of the card view.
23
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
24
     */
25
    public $rowOptions = [];
26
27
    /**
28
     * @var array the HTML attributes for the column container tag of the card view.
29
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
30
     */
31
    public $colOptions = ['class' => 's12 m6'];
32
33
    /**
34
     * @var array the HTML attributes for the card container tag of the card view.
35
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
36
     */
37
    public $options = [];
38
39
    /**
40
     * @var array the HTML attributes for the card content wrapper tag of the card view.
41
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
42
     */
43
    public $contentOptions = [];
44
45
    /**
46
     * @var string title of the card
47
     */
48
    public $cardTitle;
49
50
    /**
51
     * @var array the HTML attributes for the card title tag of the card view. Uses only if "cardTitle" attribute is specified.
52
     * @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
53
     */
54
    public $titleOptions = [];
55
56
    /**
57
     * Initializes the widget.
58
     */
59
    public function init()
60
    {
61
        parent::init();
62
63
        $options = ['class' => 'card'];
64
        Html::addCssClass($this->options, $options);
65
        $contentOptions = ['class' => 'card-content'];
66
        Html::addCssClass($this->contentOptions, $contentOptions);
67
68
        $html = Html::beginGridRow($this->rowOptions);
69
        $html .= Html::beginGridCol($this->colOptions);
70
        $html .= Html::beginTag('div', $this->options);
71
        $html .= Html::beginTag('div', $this->contentOptions);
72
73
        if (!empty($this->cardTitle)) {
74
            $titleOptions = ['class' => 'card-title'];
75
            Html::addCssClass($this->titleOptions, $titleOptions);
76
            $html .= Html::tag('span', $this->cardTitle, ['class' => 'card-title']);
77
        }
78
79
        echo $html;
80
    }
81
82
    /**
83
     * Renders the widget.
84
     */
85
    public function run()
86
    {
87
        $html = Html::endTag('div');
0 ignored issues
show
Unused Code introduced by
The assignment to $html is dead and can be removed.
Loading history...
88
        $html = Html::endTag('div');
89
        $html .= Html::endGridCol();
90
        $html .= Html::endGridRow();
91
92
        echo $html;
93
    }
94
}
95