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

WarehouseNew::parseWarehouse()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 16

Duplication

Lines 22
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 16
c 1
b 0
f 0
nc 4
nop 1
dl 22
loc 22
rs 8.9197
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