Passed
Pull Request — master (#22)
by Manuel
03:42
created

AbstractOutput::getLanguage()   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
    public function __construct(QrBill $qrBill, string $language)
20
    {
21
        $this->qrBill = $qrBill;
22
        $this->language = $language;
23
    }
24
25
    public function getQrBill() : ?QrBill
26
    {
27
        return $this->qrBill;
28
    }
29
30
    public function getLanguage(): ?string
31
    {
32
        return $this->language;
33
    }
34
35
    protected function getInformationElements() : array
36
    {
37
        $informationElements = [];
38
39
        $informationElements[] = Title::create('text.creditor');
40
        $informationElements[] = Text::create($this->qrBill->getCreditorInformation()->getFormattedIban() . "\n" . $this->qrBill->getCreditor()->getFullAddress());
41
42
        if ($this->qrBill->getPaymentReference()->getType() !== PaymentReference::TYPE_NON) {
43
            $informationElements[] = Title::create('text.reference');
44
            $informationElements[] = Text::create($this->qrBill->getPaymentReference()->getFormattedReference());
1 ignored issue
show
Bug introduced by
It seems like $this->qrBill->getPaymen...getFormattedReference() can also be of type null; however, parameter $text of Sprain\SwissQrBill\Payme...\Element\Text::create() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
            $informationElements[] = Text::create(/** @scrutinizer ignore-type */ $this->qrBill->getPaymentReference()->getFormattedReference());
Loading history...
45
        }
46
47
        if ($this->qrBill->getAdditionalInformation()) {
48
            $informationElements[] = Title::create('text.additionalInformation');
49
            $informationElements[] = Text::create($this->qrBill->getAdditionalInformation()->getFormattedString());
50
        }
51
52
        if ($this->qrBill->getUltimateDebtor()) {
53
            $informationElements[] = Title::create('text.payableBy');
54
            $informationElements[] = Text::create($this->qrBill->getUltimateDebtor()->getFullAddress());
55
        } else {
56
            $informationElements[] = Title::create('text.payableByName');
57
            $informationElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_PAYABLE_BY);
58
        }
59
60
        return $informationElements;
61
    }
62
63
    protected function getInformationElementsOfReceipt() : array
64
    {
65
        $informationElements = [];
66
67
        $informationElements[] = Title::create('text.creditor');
68
        $informationElements[] = Text::create($this->qrBill->getCreditorInformation()->getFormattedIban() . "\n" . $this->qrBill->getCreditor()->getFullAddress());
69
70
        if ($this->qrBill->getPaymentReference()->getType() !== PaymentReference::TYPE_NON) {
71
            $informationElements[] = Title::create('text.reference');
72
            $informationElements[] = Text::create($this->qrBill->getPaymentReference()->getFormattedReference());
1 ignored issue
show
Bug introduced by
It seems like $this->qrBill->getPaymen...getFormattedReference() can also be of type null; however, parameter $text of Sprain\SwissQrBill\Payme...\Element\Text::create() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

72
            $informationElements[] = Text::create(/** @scrutinizer ignore-type */ $this->qrBill->getPaymentReference()->getFormattedReference());
Loading history...
73
        }
74
75
        if ($this->qrBill->getUltimateDebtor()) {
76
            $informationElements[] = Title::create('text.payableBy');
77
            $informationElements[] = Text::create($this->qrBill->getUltimateDebtor()->getFullAddress());
78
        } else {
79
            $informationElements[] = Title::create('text.payableByName');
80
            $informationElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_PAYABLE_BY_RECEIPT);
81
        }
82
83
        return $informationElements;
84
    }
85
86
    protected function getCurrencyElements() : array
87
    {
88
        $currencyElements = [];
89
90
        $currencyElements[] = Title::create('text.currency');
91
        $currencyElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getCurrency());
92
93
        return $currencyElements;
94
    }
95
96
    protected function getAmountElements() : array
97
    {
98
        $amountElements = [];
99
100
        $amountElements[] = Title::create('text.amount');
101
102
        if ($this->qrBill->getPaymentAmountInformation()->getAmount()) {
103
            $amountElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getFormattedAmount());
104
        } else {
105
            $amountElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_AMOUNT);
106
        }
107
108
        return $amountElements;
109
    }
110
111
    protected function getAmountElementsReceipt() : array
112
    {
113
        $amountElements = [];
114
115
        $amountElements[] = Title::create('text.amount');
116
117
        if ($this->qrBill->getPaymentAmountInformation()->getAmount()) {
118
            $amountElements[] = Text::create($this->qrBill->getPaymentAmountInformation()->getFormattedAmount());
119
        } else {
120
            $amountElements[] = Placeholder::create(Placeholder::PLACEHOLDER_TYPE_AMOUNT_RECEIPT);
121
        }
122
123
        return $amountElements;
124
    }
125
126
    protected function getFurtherInformationElements() : array
127
    {
128
        $furtherInformationElements = [];
129
130
        $furtherInformationLines= [];
131
        foreach($this->qrBill->getAlternativeSchemes() as $alternativeScheme) {
132
            $furtherInformationLines[] = $alternativeScheme->getParameter();
133
        }
134
        $furtherInformationElements[] = Text::create(implode("\n", $furtherInformationLines));
135
136
        return $furtherInformationElements;
137
    }
138
}