|
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) |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
87
|
|
|
$tree->accept($this->printer); |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
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.