Passed
Push — v5 ( e348bf...8a8f01 )
by Alexey
06:35
created

Warehouse::parseWarehouse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 4
nop 1
dl 0
loc 17
rs 9.2
c 0
b 0
f 0
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 Warehouse extends \Migrations\Parser {
15
16
    public function parse() {
17
        if (is_array($this->data) && empty($this->data['@attributes'])) {
18
            foreach ($this->data as $warehouseCount) {
19
                $this->parseWarehouse($warehouseCount);
20
            }
21
        } elseif (is_array($this->data) && !empty($this->data['@attributes'])) {
22
            $this->parseWarehouse($this->data);
23
        }
24
    }
25
26
    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['@attributes']['КоличествоНаСкладе'];
28
        $objectId = \App::$cur->migrations->findObject((string)$warehouseCount['@attributes']['ИдСклада'], '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