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

WarehouseNew::parseWarehouse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
nc 4
nop 1
dl 0
loc 17
rs 9.2
c 1
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 WarehouseNew extends \Migrations\Parser {
15
16
    public function parse() {
17
        if (!\Tools::isAssoc($this->data['Остаток'])) {
0 ignored issues
show
Bug introduced by
The type Tools was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
    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