VatNumberValidatorProvider::getValidator()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
nc 3
nop 1
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gewebe\SyliusVATPlugin\Vat\Number;
6
7
class VatNumberValidatorProvider implements VatNumberValidatorProviderInterface
8
{
9
    /** @var VatNumberValidatorInterface[]|iterable */
10
    private iterable $validators;
11
12
    public function __construct(iterable $validators)
13
    {
14
        $this->validators = $validators;
15
    }
16
17
    public function getValidator(string $countryCode): ?VatNumberValidatorInterface
18
    {
19
        /** @var VatNumberValidatorInterface $validator */
20
        foreach ($this->validators as $validator) {
21
            if (in_array($countryCode, $validator->getCountries(), true)) {
22
                return $validator;
23
            }
24
        }
25
26
        return null;
27
    }
28
}
29