SavesReceipts::saveReceipt()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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