Completed
Push — master ( 98aac0...15b539 )
by Hannes
02:24
created

Writer::writeTo()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
/**
3
 * This file is part of byrokrat\autogiro\Writer.
4
 *
5
 * byrokrat\autogiro\Writer 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\Writer 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\Writer. If not, see <http://www.gnu.org/licenses/>.
17
 *
18
 * Copyright 2016 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\autogiro\Writer;
24
25
use byrokrat\autogiro\Processor\Processor;
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 Processor Helper used to validate and process tree
44
     */
45
    private $processor;
46
47
    /*public function __construct(TreeBuilder $treeBuilder, PrintingVisitor $printer, Processor $processor)
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
48
    {
49
        $this->treeBuilder = $treeBuilder;
50
        $this->printer = $printer;
51
        $this->processor = $processor;
52
    }*/
53
54
    public function deleteMandate(string $payerNr)
55
    {
56
        $this->treeBuilder->addDeleteMandateRecord($payerNr);
57
    }
58
59
    public function writeTo(OutputInterface $output)
60
    {
61
        $tree = $this->treeBuilder->buildTree();
62
63
        /*
64
            TODO
65
            det här ser bra ut, men:
66
67
            1) [KLAR] ErrorObject -> registrerar error
68
            1.5) TreeException som ersättning till ParserException
69
            2) [KLAR] (sånär som på rätt undantag...) ContainingVisitor -> hanterar errors och visitors
70
            3) [KLAR]ErrorAwareVisitor för att slippa uppning
71
            3.5) [KLAR] Interface Visitors med flag-args (kan föras över till VisitorFactory)
72
            4) För över alla processors till visitor..
73
            4.5) VisitorFactory::createVisitors(Visitors::VISITOR_IGNORE_EXTERNAL)
74
            5) ParserFactory extends VisitorFactory
75
                return new Parser(new Grammar, $this->createVisitors($flags));
76
            6) WriterFactory extends ParserFactory
77
                om vi vill använda parser för att validera att den genererade koden
78
                verkligen är så bra som vi tror...
79
            7) Glöm inte bort att skriva spec för den här klassen...
80
            8) Möjligtvis flytta upp Parser + factory till eget namespace ??
81
                då följer allting samma mall...
82
         */
83
84
        $tree->accept($this->processor);
85
86
        $this->printer->setOutput($output);
0 ignored issues
show
Bug introduced by
The method setOutput() does not seem to exist on object<byrokrat\autogiro\Writer\PrintingVisitor>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
        $tree->accept($this->printer);
88
    }
89
}
90