SaleController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 52
Duplicated Lines 25 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 5
dl 13
loc 52
ccs 0
cts 38
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A actions() 0 35 1
A behaviors() 13 13 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\controllers;
12
13
use hipanel\actions\IndexAction;
14
use hipanel\actions\SmartDeleteAction;
15
use hipanel\actions\SmartUpdateAction;
16
use hipanel\actions\ValidateFormAction;
17
use hipanel\actions\ViewAction;
18
use hipanel\filters\EasyAccessControl;
19
use hipanel\modules\client\models\stub\ClientRelationFreeStub;
20
use hipanel\modules\finance\models\Plan;
21
use Yii;
22
23
class SaleController extends \hipanel\base\CrudController
24
{
25 View Code Duplication
    public function behaviors()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        return array_merge(parent::behaviors(), [
28
            [
29
                'class' => EasyAccessControl::class,
30
                'actions' => [
31
                    'delete' => 'sale.delete',
32
                    'update' => 'sale.update',
33
                    '*' => 'sale.read',
34
                ],
35
            ],
36
        ]);
37
    }
38
39
    public function actions()
40
    {
41
        return array_merge(parent::actions(), [
42
            'index' => [
43
                'class' => IndexAction::class,
44
            ],
45
            'view' => [
46
                'class' => ViewAction::class,
47
                'data' => function ($action) {
48
                    $sale = $action->model;
49
                    $attributes = [
50
                        'id' => $sale->buyer_id,
51
                        'login' => $sale->buyer,
52
                        'seller' => $sale->seller,
53
                        'seller_id' => $sale->seller_id,
54
                    ];
55
                    $client = new ClientRelationFreeStub($attributes);
56
                    $tariff = Plan::find()->where(['id' => $sale->tariff_id])->one();
57
58
                    return compact('client', 'tariff');
59
                },
60
            ],
61
            'update' => [
62
                'class' => SmartUpdateAction::class,
63
                'success' => Yii::t('hipanel.finance.plan', 'Sale has been successfully changed'),
64
            ],
65
            'delete' => [
66
                'class' => SmartDeleteAction::class,
67
                'success' => Yii::t('hipanel:finance:sale', 'Sale was successfully deleted.'),
68
            ],
69
            'validate-form' => [
70
                'class' => ValidateFormAction::class,
71
            ],
72
        ]);
73
    }
74
}
75