Test Failed
Push — master ( 4c7907...0c8f9e )
by Alexey
05:24
created

WarehouseNew   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 61.11 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 22
loc 36
rs 10
wmc 8
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 9 4
B parseWarehouse() 22 22 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
/**
4
 * Parser Item Offer Warehouse
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
12
namespace Exchange1c\Parser\Item\Offer;
13
14
class WarehouseNew extends \Migrations\Parser {
15
16
    public function parse() {
17
        if (!\Tools::isAssoc($this->data['Остаток'])) {
18
            foreach ($this->data['Остаток'] as $warehouseCount) {
19
                $this->parseWarehouse($warehouseCount['Склад']);
20
            }
21
        } elseif (is_array($this->data['Остаток'])) {
22
            $this->parseWarehouse($this->data['Остаток']['Склад']);
23
        }
24
    }
25
26 View Code Duplication
    function parseWarehouse($warehouseCount) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
        $count = $warehouseCount['Количество'];
28
        $objectId = \App::$cur->migrations->findObject((string) $warehouseCount['Ид'], 'Ecommerce\Warehouse');
29
        if ($objectId) {
30
            $modelName = get_class($this->model);
31
            $warehouse = \Ecommerce\Item\Offer\Warehouse::get([[$modelName::index(), $this->model->pk()], [\Ecommerce\Warehouse::index(), $objectId->object_id]]);
32
            if (!$warehouse) {
33
                $warehouse = new \Ecommerce\Item\Offer\Warehouse([
34
                    $modelName::index() => $this->model->pk(),
35
                    \Ecommerce\Warehouse::index() => $objectId->object_id,
36
                    'count' => $count
37
                ]);
38
                $warehouse->save();
39
            } else {
40
                if ($warehouse->count != $count) {
41
                    $warehouse->count = $count;
42
                    $warehouse->save();
43
                }
44
            }
45
        }
46
47
    }
48
49
}
50