Customers   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 33
ccs 17
cts 17
cp 1
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A findByRfc() 0 8 3
A createItemFromStdClass() 0 3 1
A getByRfc() 0 7 2
A merge() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\Finkok\Services\Registration;
6
7
use ArrayIterator;
8
use LogicException;
9
use PhpCfdi\Finkok\Services\AbstractCollection;
10
use stdClass;
11
12
/**
13
 * @method Customer get(int $index)
14
 * @method Customer first()
15
 * @method ArrayIterator|Customer[] getIterator()
16
 * @extends AbstractCollection<Customer>
17
 */
18
class Customers extends AbstractCollection
19
{
20 19
    protected function createItemFromStdClass(stdClass $content): object
21
    {
22 19
        return new Customer($content);
23
    }
24
25 12
    public function getByRfc(string $rfc): Customer
26
    {
27 12
        $customer = $this->findByRfc($rfc);
28 12
        if (null === $customer) {
29 1
            throw new LogicException(sprintf('There is no customer with RFC %s', $rfc));
30
        }
31 11
        return $customer;
32
    }
33
34 18
    public function findByRfc(string $rfc): ?Customer
35
    {
36 18
        foreach ($this->getIterator() as $customer) {
37 14
            if ($rfc === $customer->rfc()) {
38 13
                return $customer;
39
            }
40
        }
41 8
        return null;
42
    }
43
44 2
    public function merge(self $customers): self
45
    {
46 2
        $clone = clone $this;
47 2
        foreach ($customers as $customer) {
48 2
            $clone->collection->append($customer);
49
        }
50 2
        return $clone;
51
    }
52
}
53