Passed
Push — master ( bc2c58...de2b0e )
by Carlos C
02:23 queued 12s
created

Injectors   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
rs 10
ccs 15
cts 16
cp 0.9375
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A inject() 0 7 2
A validate() 0 4 2
A isValidMember() 0 3 1
A __construct() 0 5 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate;
6
7
use InvalidArgumentException;
8
use PhpCfdi\SatCatalogosPopulate\Database\Repository;
9
use Psr\Log\LoggerInterface;
10
11
/**
12
 * @extends AbstractCollection<InjectorInterface>
13
 */
14
class Injectors extends AbstractCollection implements InjectorInterface
15
{
16 6
    public function __construct(array $members)
17
    {
18 6
        parent::__construct($members);
19 6
        if (0 === $this->count()) {
20
            throw new InvalidArgumentException('There are no injectors in the collection');
21
        }
22 6
    }
23
24 6
    public function isValidMember(mixed $member): bool
25
    {
26 6
        return ($member instanceof InjectorInterface);
27
    }
28
29 3
    public function validate(): void
30
    {
31 3
        foreach ($this->getIterator() as $injector) {
32 3
            $injector->validate();
33
        }
34 3
    }
35
36 3
    public function inject(Repository $repository, LoggerInterface $logger): int
37
    {
38 3
        $inserted = 0;
39 3
        foreach ($this->getIterator() as $injector) {
40 3
            $inserted = $inserted + $injector->inject($repository, $logger);
41
        }
42 3
        return $inserted;
43
    }
44
}
45