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

CancelTransfer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 37
loc 37
rs 10

2 Methods

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

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
 * Transfer cancel action
4
 *
5
 * @author Alexey Krupskiy <[email protected]>
6
 * @link http://inji.ru/
7
 * @copyright 2016 Alexey Krupskiy
8
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
9
 */
10
11
namespace Money;
12
13 View Code Duplication
class CancelTransfer extends \Ui\DataManager\Action
14
{
15
    public static $name = 'Отменить';
16
    public static $groupAction = true;
17
    public static $rowAction = true;
18
19
    public static function rowButton($dataManager, $item, $params)
20
    {
21
        if ($item->canceled || $item->complete) {
22
            return '';
23
        }
24
        ob_start();
25
        ?>
26
        <a onclick="inji.Server.request({
27
                url: '/admin/money/cancelTransfer/<?= $item->id; ?>',
28
                success: function () {
29
                  inji.Ui.dataManagers.reloadAll();
30
                }});
31
              return false;
32
           " href ='#' class="btn btn-xs btn-primary">Отменить</a>
33
        <?php
34
        $btn = ob_get_contents();
35
        ob_end_clean();
36
        return $btn;
37
    }
38
39
    public static function groupAction($dataManager, $ids, $actionParams)
40
    {
41
        $transfers = \Money\Transfer::getList(['where' => [['id', $ids, 'IN'], ['canceled', 0], ['complete', 0]]]);
42
        foreach ($transfers as $transfer) {
43
            $transfer->cancel();
44
        }
45
        $count = count($transfers);
46
        return 'Отменено <b>' . $count . '</b> ' . \Tools::getNumEnding($count, ['перевод', 'перевода', 'переводов']);
47
    }
48
49
}
50