Completed
Push — master ( 337c6f...93368f )
by Alexey
05:37
created

MoneyController   C

Complexity

Total Complexity 56

Size/Duplication

Total Lines 46
Duplicated Lines 56.52 %

Coupling/Cohesion

Components 0
Dependencies 14

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 56
c 3
b 0
f 1
lcom 0
cbo 14
dl 26
loc 46
rs 5.5555

3 Methods

Rating   Name   Duplication   Size   Complexity  
B manualClosePayAction() 3 17 5
B cancelTransferAction() 11 11 5
A completeTransferAction() 12 12 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like MoneyController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use MoneyController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * Money admin Controller
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class MoneyController extends adminController
12
{
13
    public function manualClosePayAction($payId)
14
    {
15
        $pay = \Money\Pay::get((int) $payId);
16
        $result = new Server\Result();
17
        if ($pay && $pay->pay_status_id == 1) {
18
            $pay->pay_status_id = 2;
19
            $pay->save();
20 View Code Duplication
            if ($pay->callback_module && $pay->callback_method) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
21
                \App::$primary->{$pay->callback_module}->{$pay->callback_method}(['status' => 'success', 'payId' => $pay->id, 'pay' => $pay]);
22
            }
23
            $result->successMsg = 'Счет был проведен';
24
            $result->send();
25
        }
26
        $result->success = false;
27
        $result->content = 'Такой счет не найден';
28
        $result->send();
29
    }
30
31 View Code Duplication
    public function cancelTransferAction($transferId)
32
    {
33
        $transfer = Money\Transfer::get($transferId);
34
        $result = new Server\Result();
35
36
        $result->success = $transfer->cancel();
37
38
        $result->successMsg = 'Перевод был отменен';
39
        $result->content = 'Не удалось отменить перевод';
40
        $result->send();
41
    }
42
43 View Code Duplication
    public function completeTransferAction($transferId)
44
    {
45
        $transfer = Money\Transfer::get($transferId);
46
47
        $result = new Server\Result();
48
49
        $result->success = $transfer->complete();
50
51
        $result->successMsg = 'Перевод был завершен';
52
        $result->content = 'Не удалось завершить перевод';
53
        $result->send();
54
    }
55
56
}
57