Completed
Push — master ( 3770db...795753 )
by Dmitry
04:13
created

PurseController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 35.71 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 20
loc 56
rs 10
c 0
b 0
f 0
ccs 14
cts 14
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
B actions() 0 31 1
A actionGenerateInvoice() 10 10 1
A actionGenerateMonthlyDocument() 10 10 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-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\controllers;
12
13
use hipanel\actions\IndexAction;
14
use hipanel\actions\RedirectAction;
15
use hipanel\actions\SmartPerformAction;
16
use hipanel\actions\SmartUpdateAction;
17
use hipanel\actions\ValidateFormAction;
18
use hipanel\actions\ViewAction;
19
use hipanel\modules\finance\models\Purse;
20
use Yii;
21
22
class PurseController extends \hipanel\base\CrudController
23
{
24 1
    public function actions()
25
    {
26
        return [
27
            'index' => [
28
                'class' => IndexAction::class,
29 1
            ],
30
            'view' => [
31
                'class' => ViewAction::class,
32 1
            ],
33
            'update' => [
34
                'class' => SmartUpdateAction::class,
35 1
            ],
36
            'update-contact' => [
37
                'class' => SmartUpdateAction::class,
38 1
            ],
39
            'update-requisite' => [
40
                'class' => SmartUpdateAction::class,
41 1
            ],
42
            'validate-form' => [
43
                'class' => ValidateFormAction::class,
44 1
            ],
45
            'invoice-archive' => [
46 1
                'class' => RedirectAction::class,
47 1
                'error' => Yii::t('hipanel', 'Under construction'),
48 1
            ],
49
            'update-monthly-document' => [
50 1
                'class'   => SmartPerformAction::class,
51 1
                'success' => Yii::t('hipanel:finance', 'Document updated'),
52 1
            ],
53 1
        ];
54
    }
55
56 View Code Duplication
    public function actionGenerateInvoice($id, $month = null)
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...
57
    {
58
        $content_type = 'application/pdf';
59
        $data = Purse::perform('generate-monthly-invoice', compact('id', 'month'));
60
        $response = Yii::$app->getResponse();
61
        $response->format = $response::FORMAT_RAW;
62
        $response->getHeaders()->add('content-type', $content_type);
63
64
        return $data;
65
    }
66
67 View Code Duplication
    public function actionGenerateMonthlyDocument($id, $type, $month = null)
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...
68
    {
69
        $content_type = 'application/pdf';
70
        $data = Purse::perform('generate-monthly-document', compact('id', 'type', 'month'));
71
        $response = Yii::$app->getResponse();
72
        $response->format = $response::FORMAT_RAW;
73
        $response->getHeaders()->add('content-type', $content_type);
74
75
        return $data;
76
    }
77
}
78