Completed
Push — master ( a88c1a...2a7402 )
by Andrii
02:44
created

SimpleBillRepository::findByIds()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 11
rs 10
1
<?php
2
/**
3
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\tests\support\bill;
12
13
use hiqdev\php\billing\bill\BillInterface;
14
use hiqdev\php\billing\bill\BillRepositoryInterface;
15
16
class SimpleBillRepository implements BillRepositoryInterface
17
{
18
    protected $bills = [];
19
20
    public function findByIds(array $ids): array
21
    {
22
        $bills = [];
23
        foreach ($ids as $id) {
24
            if (empty($this->bills[$id])) {
25
                continue;
26
            }
27
            $bills[$id] = $this->bills[$id];
28
        }
29
30
        return $bills;
31
    }
32
33
    public function save(BillInterface $bill)
34
    {
35
        $id = $bill->getId();
36
        $this->bills[$id] = $bill;
37
38
        return $id;
39
    }
40
41
    public function findByUniqueness(array $bills): array
42
    {
43
        $found = [];
44
        foreach ($this->bills as $bill) {
45
            foreach ($bills as $one) {
46
                if (#!$bill->getType()->equals($one->getType()) ||
47
                   !$bill->getTarget()->equals($one->getTarget())
48
                ) {
49
                    continue;
50
                }
51
                $found[] = $bill;
52
            }
53
        }
54
55
        return $found;
56
    }
57
}
58