Completed
Push — master ( d3dc0e...3cbdc1 )
by Andrii
04:25 queued 48s
created

BillController::actions()   B

Complexity

Conditions 6
Paths 1

Size

Total Lines 61
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 6

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 61
ccs 19
cts 19
cp 1
rs 8.6806
cc 6
eloc 38
nc 1
nop 0
crap 6

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
/*
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
                'class' => OrientationAction::class,
30
                'allowedRoutes' => [
31
                    '@bill/index'
32
                ]
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
                'class'     => ViewAction::class,
44 1
            ],
45
            'validate-form' => [
46
                '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