MenuColumn   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 45
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDataCellValue() 0 15 2
1
<?php
2
/**
3
 * Menus for Yii2.
4
 *
5
 * @link      https://github.com/hiqdev/yii2-menus
6
 * @package   yii2-menus
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\yii2\menus\grid;
12
13
use hiqdev\yii2\menus\widgets\MenuButton;
14
use yii\grid\DataColumn;
15
16
class MenuColumn extends DataColumn
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public $format = 'raw';
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public $header = '&nbsp;';
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public $contentOptions = [
32
        'class' => 'text-center',
33
    ];
34
35
    public $menuClass;
36
37
    /**
38
     * @var array
39
     */
40
    public $menuButtonOptions = [];
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getDataCellValue($model, $key, $index)
46
    {
47
        if ($this->value !== null) {
48
            return parent::getDataCellValue($model, $key, $index);
49
        } else {
50
            $class = $this->menuClass;
51
52
            return $class::widget(
53
                ['model' => $model],
54
                array_merge([
55
                    'class' => MenuButton::class,
56
                ], $this->menuButtonOptions)
57
            );
58
        }
59
    }
60
}
61