ImporterChain::getImporterForResource()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Importer;
12
13
final class ImporterChain implements ImporterChainInterface
14
{
15
    /** @var ImporterInterface[] */
16
    private $importers = [];
17
18
    public function addImporter(ImporterInterface $importer): void
19
    {
20
        $this->importers[] = $importer;
21
    }
22
23
    public function getImporterForResource(string $resourceCode): ImporterInterface
24
    {
25
        foreach ($this->importers as $importer) {
26
            if ($resourceCode === $importer->getResourceCode()) {
27
                return $importer;
28
            }
29
        }
30
31
        throw new \UnexpectedValueException(sprintf(
32
            'Importer for %s resource was not found. Make sure getResourceCode in the importer returns proper resource name',
33
            $resourceCode
34
        ));
35
    }
36
}
37