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

Injectors::getByClassname()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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