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

Item   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 87.88%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 88
ccs 29
cts 33
cp 0.8788
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCount() 0 4 1
A withCount() 0 7 1
A getDiscount() 0 4 1
A withDiscount() 0 7 1
A toArray() 0 12 3
A createFromArray() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Billogram\Model\Invoice;
6
7
use Billogram\Model\CreatableFromArray;
8
use Billogram\Model\Item\BaseItem;
9
use Billogram\Model\Item\Bookkeeping;
10
11
/**
12
 * @author Ibrahim Hizeoui <[email protected]>
13
 */
14
class Item extends BaseItem implements CreatableFromArray
15
{
16
    /**
17
     * @var int count
18
     */
19
    private $count;
20
21
    /**
22
     * @var int
23
     */
24
    private $discount;
25
26 3
    public function __construct()
27
    {
28 3
    }
29
30
    /**
31
     * @return int
32
     */
33
    public function getCount(): int
34
    {
35
        return $this->count;
36
    }
37
38
    /**
39
     * @param int $count
40
     *
41
     * @return Item
42
     */
43 2
    public function withCount(int $count)
44
    {
45 2
        $new = clone $this;
46 2
        $new->count = $count;
47
48 2
        return $new;
49
    }
50
51
    /**
52
     * @return int
53
     */
54
    public function getDiscount(): int
55
    {
56
        return $this->discount;
57
    }
58
59
    /**
60
     * @param int $discount
61
     *
62
     * @return Item
63
     */
64 2
    public function withDiscount(int $discount)
65
    {
66 2
        $new = clone $this;
67 2
        $new->discount = $discount;
68
69 2
        return $new;
70
    }
71
72 2
    public function toArray()
73
    {
74 2
        $data = parent::toArray();
75 2
        if ($this->count !== null) {
76 2
            $data['count'] = $this->count;
77
        }
78 2
        if ($this->discount !== null) {
79 2
            $data['discount'] = $this->discount;
80
        }
81
82 2
        return $data;
83
    }
84
85 3
    public static function createFromArray(array $data)
86
    {
87 3
        $item = new self();
88 3
        $item->count = $data['count'];
89 3
        $item->discount = $data['discount'];
90
        //$item = $item->withItemNo($data['item_no']) ?? null;
0 ignored issues
show
Unused Code Comprehensibility introduced by Ibrahimhizeoui
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
91 3
        $item->itemNo = $data['item_no'] ?? null;
92 3
        $item->title = $data['title'] ?? null;
93 3
        $item->description = $data['description'] ?? null;
94 3
        $item->price = $data['price'] ?? null;
95 3
        $item->vat = $data['vat'] ?? null;
96 3
        $item->unit = $data['unit'] ?? null;
97 3
        $item = $item->withBookkeeping(Bookkeeping::createFromArray($data['bookkeeping'])) ?? null;
98
99 3
        return $item;
100
    }
101
}
102