Completed
Push — master ( ecf895...d8752e )
by Hannes
03:16
created

DefaultNewOpeningRecordReader   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 0
cbo 6
dl 0
loc 34
ccs 0
cts 21
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 28 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace byrokrat\autogiro\Parser\RecordReader;
6
7
use byrokrat\autogiro\Record;
8
use byrokrat\autogiro\Parser\Matcher;
9
use byrokrat\banking\AccountFactory;
10
use byrokrat\banking\BankNames;
11
12
/**
13
 * Default opening record reader for (a number of) new layouts
14
 */
15
class DefaultNewOpeningRecordReader extends RecordReader
16
{
17
    /**
18
     * TODO Tests missing; need a plan for how different readers should be organised
19
     */
20
    public function __construct(AccountFactory $accountFactory = null)
21
    {
22
        if (!$accountFactory) {
23
            $accountFactory = new AccountFactory;
24
            $accountFactory->whitelistFormats([BankNames::FORMAT_BANKGIRO]);
25
        }
26
27
        parent::__construct(
28
            [
29
                'tc' => new Matcher\Text(1, '01'),
30
                'autogiro' => new Matcher\Text(3, str_pad('AUTOGIRO', 20, ' ')),
31
                'backup1' => new Matcher\Space(23, 2),
32
                'date' => new Matcher\Number(25, 8),
33
                'backup2' => new Matcher\Space(33, 12),
34
                'layout' => new Matcher\Text(45, str_pad('AG-MEDAVI', 20, ' ')),
35
                'customerNr' => new Matcher\Number(65, 6),
36
                'bankgiro' => new Matcher\Number(71, 10),
37
            ],
38
            function (array $values) use ($accountFactory) {
39
                return new Record\OpeningRecord(
40
                    trim($values['layout']),
41
                    \DateTimeImmutable::createFromFormat('Ymd', $values['date']),
42
                    $accountFactory->createAccount(ltrim($values['bankgiro'], '0')),
0 ignored issues
show
Compatibility introduced by
$accountFactory->createA...lues['bankgiro'], '0')) of type object<byrokrat\banking\AccountNumber> is not a sub-type of object<byrokrat\banking\Bankgiro>. It seems like you assume a concrete implementation of the interface byrokrat\banking\AccountNumber to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
43
                    ltrim($values['customerNr'], '0')
44
                );
45
            }
46
        );
47
    }
48
}
49