MarketModel   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 36
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 6 1
B getInstanceClassName() 0 20 7
1
<?php
2
3
namespace Yandex\Market\Content\Models\Base;
4
5
use Yandex\Common\Model;
6
use Yandex\Market\Content\Models\ModelSingle;
7
use Yandex\Market\Content\Models\ModelChild;
8
use Yandex\Market\Content\Models\ModelParent;
9
use Yandex\Market\Content\Models\ModelVisual;
10
use Yandex\Market\Content\Models\ModelInfo;
11
12
/**
13
 * Class MarketModel
14
 *
15
 * @package Yandex\Market\Content\Models\Base
16
 *
17
 * @author  Oleg Scherbakov <[email protected]>
18
 * @created 03.01.16 04:23
19
 *
20
 *
21
 *
22
 *
23
    ----------------------------------Instance--------------------------------------
24
    |  | ModelSingle      | ModelParent     | ModelChildren     | ModelVisual
25
    --------------------------------------------------------------------------------
26
    |  | offersCount      | offersCount        | offersCount       | offersCount
27
    --------------------------------------------------------------------------------
28
    |  | rating           | rating            | rating            | -
29
    --------------------------------------------------------------------------------
30
    |  | reviewsCount     | reviewsCount    | reviewsCount      | -
31
    --------------------------------------------------------------------------------
32
    |  | articlesCount      | articlesCount    | articlesCount     | -
33
    --------------------------------------------------------------------------------
34
    |  | isNew            | isNew            | isNew             | -
35
    --------------------------------------------------------------------------------
36
     P | vendorId         | vendorId        | vendorId            | vendorId
37
    --------------------------------------------------------------------------------
38
     R | gradeCount          | gradeCount        | gradeCount        | -
39
    --------------------------------------------------------------------------------
40
     O | categoryId       | categoryId        | categoryId        | categoryId
41
    --------------------------------------------------------------------------------
42
     P | id                  | id                | id                | id
43
    --------------------------------------------------------------------------------
44
     E | photos              | photos            | photos            | photos
45
    --------------------------------------------------------------------------------
46
     R | link              | link            | link                | link
47
    --------------------------------------------------------------------------------
48
     T | isGroup          | isGroup            | isGroup           | -
49
    --------------------------------------------------------------------------------
50
     I | vendor              | vendor            | vendor            | vendorName
51
    --------------------------------------------------------------------------------
52
     E | name              | name            | name                | name
53
    --------------------------------------------------------------------------------
54
     S | prices              | prices            | prices            | prices
55
    --------------------------------------------------------------------------------
56
    |  | description      | description        | description        | description
57
    --------------------------------------------------------------------------------
58
    |  | facts              | facts            | facts             | -
59
    --------------------------------------------------------------------------------
60
    |  | mainPhoto          | mainPhoto        | mainPhoto         | -
61
    --------------------------------------------------------------------------------
62
    |  | -                | children        | parentModel       | -
63
    --------------------------------------------------------------------------------
64
    |  | -                  | -               | -                 | previewPhotos
65
    --------------------------------------------------------------------------------
66
    |  | -                  | -               | -                 | filters
67
    --------------------------------------------------------------------------------
68
    |  | -                  | -               | -                 | offers
69
 */
70
class MarketModel extends Model
71
{
72
    /**
73
     * Return instance of model according to array structure.
74
     *
75
     * @param  array $data
76
     * @return ModelChild|ModelParent|ModelSingle|ModelVisual|ModelInfo
77
     */
78 4
    public static function getInstance($data = array())
79
    {
80 4
        $className = self::getInstanceClassName($data);
81
82 4
        return new $className($data);
83
    }
84
85 5
    public static function getInstanceClassName($data = array())
86
    {
87 5
        if (isset($data['children'])|| isset($data['modificationsCount'])) {
88 2
            return 'Yandex\Market\Content\Models\ModelParent';
89
        }
90
91 4
        if (isset($data['parentModel'])) {
92 1
            return 'Yandex\Market\Content\Models\ModelChild';
93
        }
94
95 4
        if (isset($data['offers'])) {
96 1
            return 'Yandex\Market\Content\Models\ModelVisual';
97
        }
98
99 4
        if (isset($data['offerCount']) || isset($data['type'])) {
100 1
            return 'Yandex\Market\Content\Models\ModelInfo';
101
        }
102
103 3
        return 'Yandex\Market\Content\Models\ModelSingle';
104
    }
105
}
106