PlanDetailMenu::items()   A
last analyzed

Complexity

Conditions 4
Paths 1

Size

Total Lines 53

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 53
ccs 0
cts 51
cp 0
rs 9.0254
c 0
b 0
f 0
cc 4
nc 1
nop 0
crap 20

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\menus;
12
13
use hipanel\helpers\Url;
14
use hipanel\modules\finance\models\Plan;
15
use hipanel\widgets\SettingsModal;
16
use Yii;
17
18
class PlanDetailMenu extends \hipanel\menus\AbstractDetailMenu
19
{
20
    /**
21
     * @var Plan
22
     */
23
    public $model;
24
25
    public function items()
26
    {
27
        $actions = PlanActionsMenu::create(['model' => $this->model])->items();
28
        $items = array_merge($actions, [
29
            'copy' => [
30
                'label' => SettingsModal::widget([
31
                    'model' => $this->model,
32
                    'title' => Yii::t('hipanel', 'Copy'),
33
                    'icon' => 'fa-copy fa-fw',
34
                    'scenario' => 'copy',
35
                    'handleSubmit' => false,
36
                ]),
37
                'encode' => false,
38
//                'visible' => !$this->model->isDeleted() && Yii::$app->user->can('plan.create'),
39
                'visible' => false,
40
            ],
41
            'delete' => [
42
                'label' => Yii::t('hipanel', 'Delete'),
43
                'icon' => 'fa-trash',
44
                'url' => ['@plan/delete', 'id' => $this->model->id],
45
                'encode' => false,
46
                'linkOptions' => [
47
                    'data' => [
48
                        'confirm' => Yii::t('hipanel', 'Are you sure you want to delete this item?'),
49
                        'method' => 'POST',
50
                        'pjax' => '0',
51
                    ],
52
                ],
53
                'visible' => \count($this->model->sales) === 0 && !$this->model->isDeleted() && Yii::$app->user->can('plan.delete'),
54
            ],
55
            'restore' => [
56
                'label' => Yii::t('hipanel.finance.plan', 'Restore'),
57
                'icon' => 'fa-refresh',
58
                'url' => ['@plan/restore'],
59
                'linkOptions' => [
60
                    'data' => [
61
                        'method' => 'POST',
62
                        'pjax' => '0',
63
                        'params' => ['selection[]' => $this->model->id],
64
                    ],
65
                ],
66
                'visible' => $this->model->isDeleted() && Yii::$app->user->can('plan.update'),
67
            ],
68
            'bills' => [
69
                'label' => Yii::t('hipanel:finance', 'Bills'),
70
                'icon' => 'fa-money',
71
                'url' => Url::toSearch('bill', ['tariff_id' => $this->model->id]),
72
            ],
73
        ]);
74
        unset($items['view']);
75
76
        return $items;
77
    }
78
}
79