Completed
Pull Request — master (#22)
by Manuel
04:59
created

AbstractOutput::getQrBill()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sprain\SwissQrBill\PaymentPart\Output;
4
5
use Sprain\SwissQrBill\DataGroup\Element\PaymentReference;
6
use Sprain\SwissQrBill\PaymentPart\Output\Element\Placeholder;
7
use Sprain\SwissQrBill\PaymentPart\Output\Element\Text;
8
use Sprain\SwissQrBill\PaymentPart\Output\Element\Title;
9
use Sprain\SwissQrBill\QrBill;
10
11
abstract class AbstractOutput
12
{
13
    /** @var QrBill */
14
    protected $qrBill;
15
16
    /** @var  string */
17
    protected $language;
18
19
    /** @var bool */
20
    protected $printable;
21
22
    public function __construct(QrBill $qrBill, string $language)
23
    {
24
        $this->qrBill = $qrBill;
25
        $this->language = $language;
26
        $this->printable = false;
27
    }
28
29
    public function getQrBill(): ?QrBill
30
    {
31
        return $this->qrBill;
32
    }
33
34
    public function getLanguage(): ?string
35
    {
36
        return $this->language;
37
    }
38
39
    public function setPrintable(bool $printable): self
40
    {
41
        $this->printable = $printable;
42
43
        return $this;
44
    }
45
46
    public function isPrintable(): bool
47
    {
48
        return $this->printable;
49
    }
50
51
    protected function getInformationElements(): array
52
    {
53
        $informationElements = [];
54
55
        $informationElements[] = Title::create('text.creditor');
56
        $informationElements[] = Text::create($this->qrBill->getCreditorInformation()->getFormattedIban() . "\n" . $this->qrBill->getCreditor()->getFullAddress());
57
58
        if ($this->qrBill->getPaymentReference()->getType() !== PaymentReference::TYPE_NON) {
59
            $informationElements[] = Title::create('text.reference');
60
            $informationElements[] = Text::create($this->qrBill->getPaymentReference()->getFormattedReference());
61
        }
62
63
        if ($this->qrBill->getAdditionalInformation()) {
64
            $informationElements[] = Title::create('text.additionalInformation');
65
            $informationElements[] = Text::create($this->qrBill->getAdditionalInformation()->getFormattedString());
66
        }
67
68
        if ($this->qrBill->getUltimateDebtor()) {
69
            $informationElements[] = Title::create('text.payableBy');
70
            $informationElements[] = Text::create($this->qrBill->getUltimateDebtor()->getFullAddress());
71
        } else {
72
            $informationElements[] = Title::create('text.payableByName');
73
            $informationElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_PAYABLE_BY);
74
        }
75
76
        return $informationElements;
77
    }
78
79
    protected function getInformationElementsOfReceipt(): array
80
    {
81
        $informationElements = [];
82
83
        $informationElements[] = Title::create('text.creditor');
84
        $informationElements[] = Text::create($this->qrBill->getCreditorInformation()->getFormattedIban() . "\n" . $this->qrBill->getCreditor()->getFullAddress());
85
86
        if ($this->qrBill->getPaymentReference()->getType() !== PaymentReference::TYPE_NON) {
87
            $informationElements[] = Title::create('text.reference');
88
            $informationElements[] = Text::create($this->qrBill->getPaymentReference()->getFormattedReference());
89
        }
90
91
        if ($this->qrBill->getUltimateDebtor()) {
92
            $informationElements[] = Title::create('text.payableBy');
93
            $informationElements[] = Text::create($this->qrBill->getUltimateDebtor()->getFullAddress());
94
        } else {
95
            $informationElements[] = Title::create('text.payableByName');
96
            $informationElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_PAYABLE_BY_RECEIPT);
97
        }
98
99
        return $informationElements;
100
    }
101
102
    protected function getCurrencyElements(): array
103
    {
104
        $currencyElements = [];
105
106
        $currencyElements[] = Title::create('text.currency');
107
        $currencyElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getCurrency());
108
109
        return $currencyElements;
110
    }
111
112
    protected function getAmountElements(): array
113
    {
114
        $amountElements = [];
115
116
        $amountElements[] = Title::create('text.amount');
117
118
        if ($this->qrBill->getPaymentAmountInformation()->getAmount()) {
119
            $amountElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getFormattedAmount());
120
        } else {
121
            $amountElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_AMOUNT);
122
        }
123
124
        return $amountElements;
125
    }
126
127
    protected function getAmountElementsReceipt(): array
128
    {
129
        $amountElements = [];
130
131
        $amountElements[] = Title::create('text.amount');
132
133
        if ($this->qrBill->getPaymentAmountInformation()->getAmount()) {
134
            $amountElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getFormattedAmount());
135
        } else {
136
            $amountElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_AMOUNT_RECEIPT);
137
        }
138
139
        return $amountElements;
140
    }
141
142
    protected function getFurtherInformationElements(): array
143
    {
144
        $furtherInformationElements = [];
145
146
        $furtherInformationLines= [];
147
        foreach($this->qrBill->getAlternativeSchemes() as $alternativeScheme) {
148
            $furtherInformationLines[] = $alternativeScheme->getParameter();
149
        }
150
        $furtherInformationElements[] = Text::create(implode("\n", $furtherInformationLines));
151
152
        return $furtherInformationElements;
153
    }
154
}