Passed
Push — master ( 9ff768...b736eb )
by Laurens
02:33
created

PurchaseHistory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 45
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A getFirstPurchaseHash() 0 4 1
A getLastPurchaseHash() 0 4 1
A addPurchase() 0 4 1
A removePurchase() 0 4 1
A getPurchases() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\API\Purchase;
6
7
final class PurchaseHistory
8
{
9
    private $firstPurchaseHash;
10
    private $lastPurchaseHash;
11
    private $purchases;
12
13 3
    public function __construct(
14
        string $firstPurchaseHash,
15
        string $lastPurchaseHash,
16
        array $purchases
17
    ) {
18 3
        $this->firstPurchaseHash = $firstPurchaseHash;
19 3
        $this->lastPurchaseHash = $lastPurchaseHash;
20
21 3
        foreach ($purchases as $purchase) {
22 1
            if ($purchase instanceof Purchase) {
23 1
                $this->addPurchase($purchase);
24
            }
25
        }
26 3
    }
27
28 1
    public function getFirstPurchaseHash(): string
29
    {
30 1
        return $this->firstPurchaseHash;
31
    }
32
33 1
    public function getLastPurchaseHash(): string
34
    {
35 1
        return $this->lastPurchaseHash;
36
    }
37 1
    public function addPurchase(Purchase $purchase): void
38
    {
39 1
        $this->purchases[(string) $purchase->getUuid()] = $purchase;
40 1
    }
41
42 1
    public function removePurchase(Purchase $purchase): void
43
    {
44 1
        unset($this->purchases[(string)$purchase->getUuid()]);
45 1
    }
46
47 1
    public function getPurchases(): array
48
    {
49 1
        return $this->purchases;
50
    }
51
}
52