Completed
Push — master ( 168b8f...f2b799 )
by Tobias
02:41
created

Item::createFromArray()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 15
cts 15
cp 1
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 15
nc 16
nop 1
crap 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Item;
6
7
/**
8
 * @author Ibrahim Hizeoui <[email protected]>
9
 */
10
class Item extends BaseItem
11
{
12 5
    public static function createFromArray(array $data)
13
    {
14 5
        if (array_key_exists('data', $data)) {
15 4
            $data = $data['data'];
16
        }
17
18 5
        $item = new self();
19 5
        $item->itemNo = $data['item_no'] ?? null;
20 5
        $item->title = $data['title'] ?? null;
21 5
        $item->description = $data['description'] ?? null;
22 5
        $item->price = $data['price'] ?? null;
23 5
        $item->vat = $data['vat'] ?? null;
24 5
        $item->unit = $data['unit'] ?? null;
25 5
        $item->createdAt = isset($data['created_at']) ? new \DateTime($data['created_at']) : null;
26 5
        $item->updatedAt = isset($data['updated_at']) ? new \DateTime($data['updated_at']) : null;
27
28 5
        if (array_key_exists('bookkeeping', $data)) {
29 4
            $item->bookkeeping = Bookkeeping::createFromArray($data['bookkeeping']);
30
        }
31
32 5
        return $item;
33
    }
34
}
35