SaleController::behaviors()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 0
cts 12
cp 0
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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