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

Injectors::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 0
crap 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