Completed
Push — master ( e814e0...e87053 )
by Mārtiņš
01:53
created

ArtworkItem::fromArray()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 26
rs 8.8571
cc 1
eloc 18
nc 1
nop 1
1
<?php
2
3
4
namespace Inktale\Api\Structures;
5
6
7
class ArtworkItem extends AbstractBaseItem
8
{
9
    /**
10
     * @var string
11
     */
12
    public $artworkId;
13
14
    /**
15
     * Display name
16
     *
17
     * @var string
18
     */
19
    public $name;
20
21
    /**
22
     * Is publicly visible
23
     *
24
     * @var bool
25
     */
26
    public $isPublic;
27
28
    /**
29
     * Is processing files or products
30
     *
31
     * @var bool
32
     */
33
    public $isProcessing;
34
35
    /**
36
     * Public description
37
     *
38
     * @var string
39
     */
40
    public $description;
41
42
    /**
43
     * Public URL to artwork page
44
     *
45
     * @var string
46
     */
47
    public $url;
48
49
    /**
50
     * List of keywords
51
     *
52
     * @var string[]
53
     */
54
    public $keywords;
55
56
    /**
57
     * Main artwork file (displayed in artwork public page)
58
     * If artwork is still processing, this value can be missing
59
     *
60
     * @var ArtworkFileItem
61
     */
62
    public $mainArtworkFile;
63
64
    /**
65
     * List of additional artwork files throughout all products (if set)
66
     * If artwork is still processing, values can be missing
67
     *
68
     * @var ArtworkFileItem[]
69
     */
70
    public $artworkFiles = [];
71
72
    /**
73
     * Artwork products currently enabled
74
     *
75
     * @var ArtworkProductItem[]
76
     */
77
    public $artworkProducts = [];
78
79
    /**
80
     * @param array|mixed $raw
81
     * @return ArtworkItem
82
     */
83
    static function fromArray($raw)
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...
84
    {
85
        $item = new self;
86
87
        $item->raw = $raw;
0 ignored issues
show
Documentation Bug introduced by
It seems like $raw of type * is incompatible with the declared type array of property $raw.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
88
89
        $item->artworkId = $raw['artworkId'];
90
        $item->name = $raw['name'];
91
        $item->isPublic = (bool)$raw['isPublic'];
92
        $item->isProcessing = (bool)$raw['isProcessing'];
93
        $item->description = $raw['description'];
94
        $item->url = $raw['url'];
95
        $item->keywords= $raw['keywords'];
96
97
        $item->mainArtworkFile = ArtworkFileItem::fromArray($raw['mainArtworkFile']);
98
99
        $item->artworkFiles = array_map(function ($v) {
100
            return ArtworkFileItem::fromArray($v);
101
        }, $raw['artworkFiles']);
102
103
        $item->artworkProducts = array_map(function ($v) {
104
            return ArtworkProductItem::fromArray($v);
105
        }, $raw['artworkProducts']);
106
107
        return $item;
108
    }
109
}