Completed
Push — master ( e87053...ec70af )
by Mārtiņš
02:10
created

ArtworkListItem::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 10
nc 1
nop 1
1
<?php
2
3
4
namespace Inktale\Api\Structures;
5
6
7
class ArtworkListItem extends AbstractBaseItem
8
{
9
    /**
10
     * @var int
11
     */
12
    public $page;
13
14
    /**
15
     * @var int
16
     */
17
    public $perPage;
18
19
    /**
20
     * @var int
21
     */
22
    public $totalPages;
23
24
    /**
25
     * Total item count within all pages
26
     *
27
     * @var int
28
     */
29
    public $total;
30
31
    /**
32
     * Partially filled artwork item
33
     *
34
     * @var ArtworkItem[]
35
     */
36
    public $items = [];
37
38
    /**
39
     * @param array|mixed $raw
40
     * @return ArtworkListItem
41
     */
42
    public static function fromArray($raw)
43
    {
44
        $item = new self;
45
46
        $item->page = (int)$raw['pagination']['page'];
47
        $item->perPage = (int)$raw['pagination']['perPage'];
48
        $item->totalPages = (int)$raw['pagination']['totalPages'];
49
        $item->total = (int)$raw['pagination']['total'];
50
51
        $item->items = array_map(function ($v) {
52
            return ArtworkItem::fromArray($v);
53
        }, $raw['artworks']);
54
55
        return $item;
56
    }
57
}