Total Complexity | 7 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class CustomerFixturePool |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * @var CustomerFixture[] |
||
14 | */ |
||
15 | private $customerFixtures = []; |
||
16 | |||
17 | 7 | public function add(CustomerInterface $customer, string $key = null): void |
|
18 | { |
||
19 | 7 | if ($key === null) { |
|
20 | 5 | $this->customerFixtures[] = new CustomerFixture($customer); |
|
21 | } else { |
||
22 | 2 | $this->customerFixtures[$key] = new CustomerFixture($customer); |
|
23 | } |
||
24 | 7 | } |
|
25 | |||
26 | /** |
||
27 | * Returns customer fixture by key, or last added if key not specified |
||
28 | * |
||
29 | * @param string|null $key |
||
30 | * @return CustomerFixture |
||
31 | */ |
||
32 | 7 | public function get(string $key = null): CustomerFixture |
|
33 | { |
||
34 | 7 | if ($key === null) { |
|
35 | 5 | $key = \array_key_last($this->customerFixtures); |
|
36 | } |
||
37 | 7 | if ($key === null || !array_key_exists($key, $this->customerFixtures)) { |
|
38 | 3 | throw new \OutOfBoundsException('No matching customer found in fixture pool'); |
|
39 | } |
||
40 | 4 | return $this->customerFixtures[$key]; |
|
41 | } |
||
42 | |||
43 | 4 | public function rollback(): void |
|
47 | 4 | } |
|
48 | } |
||
49 |