Passed
Pull Request — master (#99)
by
unknown
02:46
created

SimpleBillRepository   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 20
c 4
b 0
f 0
dl 0
loc 45
rs 10
wmc 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-2020, 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
use hiqdev\DataMapper\Query\Specification;
16
17
class SimpleBillRepository implements BillRepositoryInterface
18
{
19
    protected $bills = [];
20
21
    public function findByIds(array $ids): array
22
    {
23
        $bills = [];
24
        foreach ($ids as $id) {
25
            if (empty($this->bills[$id])) {
26
                continue;
27
            }
28
            $bills[$id] = $this->bills[$id];
29
        }
30
31
        return $bills;
32
    }
33
34
    public function save(BillInterface $bill)
35
    {
36
        $this->bills[$bill->getUniqueString()] = $bill;
37
38
        return $bill->getId();
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 (
47
                    !$bill->getType()->equals($one->getType()) ||
48
                    !$bill->getTarget()->equals($one->getTarget())
49
                ) {
50
                    continue;
51
                }
52
                $found[] = $bill;
53
            }
54
        }
55
56
        return $found;
57
    }
58
59
    public function findAll(Specification $specification): array
60
    {
61
        return $this->bills;
62
    }
63
}
64