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

MandateResponseStrategy::createStates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 9
ccs 0
cts 4
cp 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace byrokrat\autogiro\Parser\Strategy;
6
7
use byrokrat\autogiro\Layouts;
8
use byrokrat\autogiro\Section;
9
use byrokrat\autogiro\Line;
10
use byrokrat\autogiro\Parser\RecordReader;
11
use byrokrat\autogiro\Parser\StateMachine;
12
13
/**
14
 * Strategy for parsing responses to previously made mandate requests
15
 */
16
class MandateResponseStrategy implements Strategy, Layouts
17
{
18
    /**
19
     * @var Section
20
     */
21
    private $section;
22
23
    /**
24
     * @var RecordReader\RecordReader;
25
     */
26
    private $openingRecordReader;
27
28
    public function __construct(RecordReader\RecordReader $openingRecordReader = null)
29
    {
30
        // TODO When we have a factory pattern for creating strategies there should be no default reader here...
31
        $this->openingRecordReader = $openingRecordReader ?: new RecordReader\DefaultNewOpeningRecordReader;
32
    }
33
34
    public function createStates(): StateMachine
35
    {
36
        return new StateMachine([
37
            StateMachine::STATE_INIT => ['01'],
38
            '01' => ['73', '09'],
39
            '73' => ['73', '09'],
40
            '09' => [StateMachine::STATE_DONE]
41
        ]);
42
    }
43
44
    public function begin()
45
    {
46
        $this->section = new Section(self::LAYOUT_MANDATE_RESPONSE);
47
    }
48
49
    public function on01(Line $line)
50
    {
51
        $this->section->setOpeningRecord($this->openingRecordReader->readRecord($line));
52
    }
53
54
    public function on73(Line $line)
0 ignored issues
show
Unused Code introduced by
The parameter $line is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
55
    {
56
        // TODO implement parsing 73-records
57
    }
58
59
    public function on09(Line $line)
0 ignored issues
show
Unused Code introduced by
The parameter $line is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
60
    {
61
        // TODO implement parsing 09-records
62
    }
63
64
    public function done(): Section
65
    {
66
        return $this->section;
67
    }
68
}
69