SavesReceipts   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 30
c 0
b 0
f 0
rs 10
ccs 6
cts 6
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A saveReceipt() 0 3 1
A receiptFor() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Courier;
6
7
use Courier\Exceptions\ReceiptException;
8
use PhpEmail\Email;
9
10
trait SavesReceipts
11
{
12
    /**
13
     * @var string[]
14
     */
15
    protected $receipts = [];
16
17
    /**
18
     * @param Email  $email
19
     * @param string $receipt
20
     *
21
     * @return void
22
     */
23 2
    protected function saveReceipt(Email $email, string $receipt): void
24
    {
25 2
        $this->receipts[spl_object_hash($email)] = $receipt;
26
    }
27
28
    /**
29
     * @param Email $email
30
     *
31
     * @return string
32
     */
33 3
    public function receiptFor(Email $email): string
34
    {
35 3
        if ($receipt = $this->receipts[spl_object_hash($email)] ?? null) {
36 2
            return $receipt;
37
        }
38
39 1
        throw new ReceiptException();
40
    }
41
}
42