Completed
Push — master ( f81666...55a9f3 )
by Alexey
05:42
created

ClosePayBtn   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 53.66 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 4
dl 22
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A rowButton() 19 19 2
A groupAction() 3 13 4

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
 * Item name
4
 *
5
 * Info
6
 *
7
 * @author Alexey Krupskiy <[email protected]>
8
 * @link http://inji.ru/
9
 * @copyright 2016 Alexey Krupskiy
10
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
11
 */
12
13
namespace Money;
14
15
class ClosePayBtn extends \Ui\DataManager\Action
16
{
17
    public static $name = 'Оплачено';
18
    public static $groupAction = true;
19
    public static $rowAction = true;
20
21 View Code Duplication
    public static function rowButton($dataManager, $item, $params)
22
    {
23
        if ($item->pay_status_id != 1) {
24
            return '';
25
        }
26
        ob_start();
27
        ?>
28
        <a onclick="inji.Server.request({
29
                        url: '/admin/money/manualClosePay/<?= $item->id; ?>',
30
                        success: function () {
31
                          inji.Ui.dataManagers.reloadAll();
32
                        }});
33
                      return false;
34
           " href ='#' class="btn btn-xs btn-primary">Оплачено</a>
35
        <?php
36
        $btn = ob_get_contents();
37
        ob_end_clean();
38
        return $btn;
39
    }
40
41
    public static function groupAction($dataManager, $ids, $actionParams)
42
    {
43
        $pays = Pay::getList(['where' => [['id', $ids, 'IN'], ['pay_status_id', 1]]]);
44
        foreach ($pays as $pay) {
45
            $pay->pay_status_id = 2;
46
            $pay->save();
47 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...
48
                \App::$primary->{$pay->callback_module}->{$pay->callback_method}(['status' => 'success', 'payId' => $pay->id, 'pay' => $pay]);
49
            }
50
        }
51
        $count = count($pays);
52
        return 'Оплачено <b>' . $count . '</b> ' . \Tools::getNumEnding($pays, ['счет', 'счета', 'счетов']);
53
    }
54
55
}
56