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

FormatContainer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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