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

FormatContainer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFormatFromClearing() 0 10 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