Completed
Push — master ( 9c11ba...e3a974 )
by Hannes
01:54
created

Writer::deletePayments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 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-18 Hannes Forsgård
19
 */
20
21
declare(strict_types = 1);
22
23
namespace byrokrat\autogiro\Writer;
24
25
use byrokrat\autogiro\Intervals;
26
use byrokrat\autogiro\Visitor\VisitorInterface;
27
use byrokrat\banking\AccountNumber;
28
use byrokrat\id\IdInterface;
29
use byrokrat\amount\Currency\SEK;
30
31
class Writer implements WriterInterface
32
{
33
    /**
34
     * @var TreeBuilder Helper used when building trees
35
     */
36
    private $treeBuilder;
37
38
    /**
39
     * @var PrintingVisitor Helper used when generating content
40
     */
41
    private $printer;
42
43
    /**
44
     * @var VisitorInterface Helper used to validate and process tree
45
     */
46
    private $visitor;
47
48
    public function __construct(TreeBuilder $treeBuilder, PrintingVisitor $printer, VisitorInterface $visitor)
49
    {
50
        $this->treeBuilder = $treeBuilder;
51
        $this->printer = $printer;
52
        $this->visitor = $visitor;
53
    }
54
55
    public function getContent(): string
56
    {
57
        $tree = $this->treeBuilder->buildTree();
58
        $tree->accept($this->visitor);
59
        $output = new Output;
60
        $this->printer->setOutput($output);
61
        $tree->accept($this->printer);
62
63
        return rtrim($output->getContent(), "\r\n");
64
    }
65
66
    public function reset(): void
67
    {
68
        $this->treeBuilder->reset();
69
    }
70
71
    public function addNewMandate(string $payerNr, AccountNumber $account, IdInterface $id): void
72
    {
73
        $this->treeBuilder->addCreateMandateRequest($payerNr, $account, $id);
74
    }
75
76
    public function deleteMandate(string $payerNr): void
77
    {
78
        $this->treeBuilder->addDeleteMandateRequest($payerNr);
79
    }
80
81
    public function acceptDigitalMandate(string $payerNr): void
82
    {
83
        $this->treeBuilder->addAcceptDigitalMandateRequest($payerNr);
84
    }
85
86
    public function rejectDigitalMandate(string $payerNr): void
87
    {
88
        $this->treeBuilder->addRejectDigitalMandateRequest($payerNr);
89
    }
90
91
    public function updateMandate(string $payerNr, string $newPayerNr): void
92
    {
93
        $this->treeBuilder->addUpdateMandateRequest($payerNr, $newPayerNr);
94
    }
95
96 View Code Duplication
    public function addPayment(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
        string $payerNr,
98
        SEK $amount,
99
        \DateTimeInterface $date,
100
        string $ref = '',
101
        string $interval = Intervals::INTERVAL_ONCE,
102
        int $repetitions = 0
103
    ): void {
104
        $this->treeBuilder->addIncomingPaymentRequest($payerNr, $amount, $date, $ref, $interval, $repetitions);
105
    }
106
107
    public function addMonthlyPayment(string $payerNr, SEK $amount, \DateTimeInterface $date, string $ref = ''): void
108
    {
109
        $this->addPayment($payerNr, $amount, $date, $ref, Intervals::INTERVAL_MONTHLY_ON_DATE, 0);
110
    }
111
112
    public function addImmediatePayment(string $payerNr, SEK $amount, string $ref = ''): void
113
    {
114
        $this->treeBuilder->addImmediateIncomingPaymentRequest($payerNr, $amount, $ref);
115
    }
116
117 View Code Duplication
    public function addOutgoingPayment(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
        string $payerNr,
119
        SEK $amount,
120
        \DateTimeInterface $date,
121
        string $ref = '',
122
        string $interval = Intervals::INTERVAL_ONCE,
123
        int $repetitions = 0
124
    ): void {
125
        $this->treeBuilder->addOutgoingPaymentRequest($payerNr, $amount, $date, $ref, $interval, $repetitions);
126
    }
127
128
    public function addImmediateOutgoingPayment(string $payerNr, SEK $amount, string $ref = ''): void
129
    {
130
        $this->treeBuilder->addImmediateOutgoingPaymentRequest($payerNr, $amount, $ref);
131
    }
132
133
    public function deletePayments(string $payerNr): void
134
    {
135
        $this->treeBuilder->addDeletePaymentRequest($payerNr);
136
    }
137
}
138