InvoiceFixturePool   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 32
ccs 11
cts 11
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 6 2
A get() 0 9 4
1
<?php
2
declare(strict_types=1);
3
4
namespace TddWizard\Fixtures\Sales;
5
6
use Magento\Sales\Api\Data\InvoiceInterface;
7
8
class InvoiceFixturePool
9
{
10
11
    /**
12
     * @var InvoiceFixture[]
13
     */
14
    private $invoiceFixtures = [];
15
16 3
    public function add(InvoiceInterface $invoice, string $key = null): void
17
    {
18 3
        if ($key === null) {
19 1
            $this->invoiceFixtures[] = new InvoiceFixture($invoice);
20
        } else {
21 2
            $this->invoiceFixtures[$key] = new InvoiceFixture($invoice);
22
        }
23 3
    }
24
25
    /**
26
     * Returns invoice fixture by key, or last added if key not specified
27
     *
28
     * @param string|null $key
29
     * @return InvoiceFixture
30
     */
31 4
    public function get(string $key = null): InvoiceFixture
32
    {
33 4
        if ($key === null) {
34 2
            $key = \array_key_last($this->invoiceFixtures);
35
        }
36 4
        if ($key === null || !array_key_exists($key, $this->invoiceFixtures)) {
37 2
            throw new \OutOfBoundsException('No matching invoice found in fixture pool');
38
        }
39 2
        return $this->invoiceFixtures[$key];
40
    }
41
}
42