Completed
Push — master ( 156270...ac2069 )
by Andrii
04:03
created

BillController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 52.17%

Importance

Changes 6
Bugs 0 Features 3
Metric Value
wmc 8
c 6
b 0
f 3
lcom 0
cbo 2
dl 0
loc 72
ccs 24
cts 46
cp 0.5217
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B actions() 0 61 6
A getPaymentType() 0 4 2
1
<?php
2
3
/*
4
 * Finance module for HiPanel
5
 *
6
 * @link      https://github.com/hiqdev/hipanel-module-finance
7
 * @package   hipanel-module-finance
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\modules\finance\controllers;
13
14
use hipanel\actions\IndexAction;
15
use hipanel\actions\OrientationAction;
16
use hipanel\actions\SmartCreateAction;
17
use hipanel\actions\SmartPerformAction;
18
use hipanel\actions\SmartUpdateAction;
19
use hipanel\actions\ValidateFormAction;
20
use hipanel\actions\ViewAction;
21
use Yii;
22
23
class BillController extends \hipanel\base\CrudController
24
{
25 1
    public function actions()
26
    {
27
        return [
28
            'set-orientation' => [
29 1
                'class' => OrientationAction::class,
30
                'allowedRoutes' => [
31 1
                    '@bill/index'
32 1
                ]
33 1
            ],
34
            'index' => [
35 1
                'class'     => IndexAction::class,
36
                'data'      => function ($action) {
37
                    return [
38
                        'type' => $action->controller->getPaymentType(),
39
                    ];
40 1
                },
41 1
            ],
42
            'view' => [
43 1
                'class'     => ViewAction::class,
44 1
            ],
45
            'validate-form' => [
46 1
                'class'     => ValidateFormAction::class,
47 1
            ],
48
            'create' => [
49 1
                'class'     => SmartCreateAction::class,
50 1
                'data' => function ($action) {
0 ignored issues
show
Unused Code introduced by
The parameter $action 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...
51
                    $types = $this->getRefs('type,bill', 'hipanel/finance', ['with_hierarchy' => 1, 'orderby' => 'name_asc']);
52
                    $billTypes = [];
53
                    $billGroupLabels = [];
54
55
                    foreach ($types as $key => $title) {
56
                        list($type, $name) = explode(',', $key);
57
58
                        if (!isset($billTypes[$type])) {
59
                            $billTypes[$type] = [];
60
                            $billGroupLabels[$type] = ['label' => $title];
61
                        }
62
63
                        if (isset($name)) {
64
                            foreach ($types as $k => $t) {
65
                                if (strpos($k, $type . ',') === 0) {
66
                                    $billTypes[$type][$k] = $t;
67
                                }
68
                            }
69
                        }
70
                    }
71
72
                    return ['billTypes' => $billTypes, 'billGroupLabels' => $billGroupLabels];
73 1
                },
74 1
                'success'   => Yii::t('hipanel/finance', 'Bill was created successfully'),
75 1
            ],
76
            'update' => [
77 1
                'class'     => SmartUpdateAction::class,
78 1
                'success'   => Yii::t('hipanel/finance', 'Bill was updated successfully'),
79 1
            ],
80
            'delete' => [
81 1
                'class'     => SmartPerformAction::class,
82 1
                'success'   => Yii::t('hipanel/finance', 'Bill was deleted successfully'),
83 1
            ],
84 1
        ];
85
    }
86
87
    /**
88
     * @return array
89
     */
90
    public function getPaymentType()
91
    {
92
        return $this->getRefs('type,bill', 'hipanel/finance', Yii::$app->user->can('support') ? ['with_hierarchy' => true] : []);
93
    }
94
}
95