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

Writer   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 107
Duplicated Lines 18.69 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 20
loc 107
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 4

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getContent() 0 10 1
A reset() 0 4 1
A addNewMandate() 0 4 1
A deleteMandate() 0 4 1
A acceptDigitalMandate() 0 4 1
A rejectDigitalMandate() 0 4 1
A updateMandate() 0 4 1
A addPayment() 10 10 1
A addMonthlyPayment() 0 4 1
A addImmediatePayment() 0 4 1
A addOutgoingPayment() 10 10 1
A addImmediateOutgoingPayment() 0 4 1
A deletePayments() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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