Completed
Push — master ( d192c7...9930d3 )
by Alexey
05:16
created

Warehouse   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 32.14 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 2 Features 0
Metric Value
c 2
b 2
f 0
dl 9
loc 28
rs 10
wmc 6
lcom 1
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 9 24 6

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 Warehouse extends \Migrations\Parser
15
{
16
    public function parse()
17
    {
18
        if (is_array($this->data) && empty($this->data['@attributes'])) {
19
            foreach ($this->data as $warehouseCount) {
20
                $count = $warehouseCount['@attributes']['КоличествоНаСкладе'];
21
22
                $objectId = \Migrations\Id::get([['parse_id', (string) $warehouseCount['@attributes']['ИдСклада']], ['type', 'Ecommerce\Warehouse']]);
23
                if ($objectId) {
24
                    $modelName = get_class($this->model);
25
                    $warehouse = \Ecommerce\Item\Offer\Warehouse::get([[$modelName::index(), $this->model->pk()], [\Ecommerce\Warehouse::index(), $objectId->object_id]]);
26 View Code Duplication
                    if (!$warehouse) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
                        $warehouse = new \Ecommerce\Item\Offer\Warehouse([
28
                            $modelName::index() => $this->model->pk(),
29
                            \Ecommerce\Warehouse::index() => $objectId->object_id,
30
                            'count' => $count
31
                        ]);
32
                    } else {
33
                        $warehouse->count = $count;
34
                    }
35
                    $warehouse->save();
36
                }
37
            }
38
        }
39
    }
40
41
}
42