Completed
Push — master ( c13142...c0435c )
by Tobias
02:34
created

Item::withBookkeeping()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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
            $itemArray = $data['data'];
16
        } else {
17 1
            $itemArray = $data;
18
        }
19 5
        $item = new self();
20 5
        $item->itemNo = $itemArray['item_no'] ?? null;
21 5
        $item->title = $itemArray['title'] ?? null;
22 5
        $item->description = $itemArray['description'] ?? null;
23 5
        $item->price = $itemArray['price'] ?? null;
24 5
        $item->vat = $itemArray['vat'] ?? null;
25 5
        $item->unit = $itemArray['unit'] ?? null;
26 5
        if (array_key_exists('bookkeeping', $itemArray)) {
27 4
            $item->bookkeeping = Bookkeeping::createFromArray($itemArray['bookkeeping']);
28
        }
29 5
        $item->createdAt = $itemArray['created_at'] ?? null;
30 5
        $item->updatedAt = $itemArray['updated_at'] ?? null;
31
32 5
        return $item;
33
    }
34
}
35