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

CloseCartBtn   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 46.34 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

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

2 Methods

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

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 Ecommerce;
14
15
class CloseCartBtn 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 (\App::$cur->Exchange1c) {
24
            return '';
25
        }
26
        ob_start();
27
        ?>
28
        <a onclick="inji.Server.request({
29
                        url: '/admin/ecommerce/closeCart/<?= $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
        if (\App::$cur->Exchange1c) {
44
            throw new \Exception('Недоступно при подключенной 1с');
45
        }
46
        $carts = Cart::getList(['where' => [['id', $ids, 'IN'], ['cart_status_id', 5, '!=']]]);
47
        foreach ($carts as $cart) {
48
            $cart->cart_status_id = 5;
49
            $cart->save();
50
        }
51
        $count = count($carts);
52
        return 'Завершено <b>' . $count . '</b> ' . \Tools::getNumEnding($count, ['корзина', 'корзины', 'корзин']);
53
    }
54
55
}
56