|
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')), |
|
|
|
|
|
|
43
|
|
|
ltrim($values['customerNr'], '0') |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
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.