SavesReceipts::receiptFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
rs 10
ccs 4
cts 4
cp 1
cc 2
nc 2
nop 1
crap 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