Completed
Push — master ( 5d18c7...cabcf3 )
by Hannes
16s queued 13s
created

FormatContainer::getFormatFromClearing()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
ccs 5
cts 5
cp 1
crap 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace byrokrat\banking\Format;
6
7
use byrokrat\banking\AccountNumber;
8
use byrokrat\banking\Exception\InvalidClearingNumberException;
9
10
/**
11
 * Container of format object
12
 */
13
class FormatContainer
14
{
15
    /**
16
     * @var FormatInterface[];
17
     */
18
    private $formats;
19
20 3
    public function __construct(FormatInterface ...$formats)
21
    {
22 3
        $this->formats = $formats;
23 3
    }
24
25 143
    public function getFormatFromClearing(AccountNumber $account): FormatInterface
26
    {
27 143
        foreach ($this->formats as $format) {
28 142
            if ($format->isValidClearing($account)) {
29 142
                return $format;
30
            }
31
        }
32
33 1
        throw new InvalidClearingNumberException("Unknown clearing number: '{$account->getClearingNumber()}'");
34
    }
35
}
36