Completed
Push — master ( a96a4d...7dbffa )
by Hannes
02:13
created

Writer::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/**
3
 * This file is part of byrokrat\autogiro.
4
 *
5
 * byrokrat\autogiro is free software: you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License as published
7
 * by the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * byrokrat\autogiro is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with byrokrat\autogiro. If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Copyright 2016-17 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\autogiro\Writer;
24
25
use byrokrat\autogiro\Visitor\Visitor;
26
27
/**
28
 * Facade for creating autogiro request files
29
 */
30
class Writer
31
{
32
    /**
33
     * @var TreeBuilder Helper used when building trees
34
     */
35
    private $treeBuilder;
36
37
    /**
38
     * @var PrintingVisitor Helper used when generating content
39
     */
40
    private $printer;
41
42
    /**
43
     * @var Visitor Helper used to validate and process tree
44
     */
45
    private $visitor;
46
47
    public function __construct(TreeBuilder $treeBuilder, PrintingVisitor $printer, Visitor $visitor)
48
    {
49
        $this->treeBuilder = $treeBuilder;
50
        $this->printer = $printer;
51
        $this->visitor = $visitor;
52
    }
53
54
    /**
55
     * Build and return request content
56
     */
57
    public function getContent(): string
58
    {
59
        $tree = $this->treeBuilder->buildTree();
60
        $tree->accept($this->visitor);
61
        $output = new Output;
62
        $this->printer->setOutput($output);
63
        $tree->accept($this->printer);
64
65
        return $output->getContent();
66
    }
67
68
    /**
69
     * Reset internal build queue
70
     */
71
    public function reset()
72
    {
73
        $this->treeBuilder->reset();
74
    }
75
76
    /**
77
     * Add a delete mandate request to the build queue
78
     */
79
    public function deleteMandate(string $payerNr)
80
    {
81
        $this->treeBuilder->addDeleteMandateRecord($payerNr);
82
    }
83
}
84