Passed
Pull Request — master (#22)
by Manuel
02:21 queued 46s
created

AbstractOutput::getInformationElementsOfReceipt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sprain\SwissQrBill\PaymentPart\Output;
4
5
use Sprain\SwissQrBill\QrBill;
6
7
abstract class AbstractOutput
8
{
9
    /** @var QrBill */
10
    protected $qrBill;
11
12
    /** @var  string */
13
    protected $language;
14
15
    public function __construct(QrBill $qrBill, string $language)
16
    {
17
        $this->qrBill = $qrBill;
18
        $this->language = $language;
19
    }
20
21
    public function getQrBill() : ?QrBill
22
    {
23
        return $this->qrBill;
24
    }
25
26
    public function getLanguage(): ?string
27
    {
28
        return $this->language;
29
    }
30
31
    protected function getInformationElements() : array
32
    {
33
        $informationElements = [];
34
35
        $availableInformationElements =  [
36
            'text.creditor' => $this->qrBill->getCreditorInformation()->getFormattedIban() . "\n" . $this->qrBill->getCreditor()->getFullAddress(),
37
            'text.reference' => $this->qrBill->getPaymentReference()->getFormattedReference(),
38
            'text.additionalInformation' => $this->qrBill->getAdditionalInformation() ? $this->qrBill->getAdditionalInformation()->getMessage() : null,
39
            'text.payableBy' => $this->qrBill->getUltimateDebtor() ? $this->qrBill->getUltimateDebtor()->getFullAddress() : null,
40
        ];
41
42
        foreach($availableInformationElements as $key => $content) {
43
            if ($content) {
44
                $informationElements[$key] = $content;
45
            }
46
        }
47
48
        return $informationElements;
49
    }
50
51
    protected function getInformationElementsOfReceipt() : array
52
    {
53
        $informationElements = $this->getInformationElements();
54
        unset($informationElements['text.additionalInformation']);
55
56
        return $informationElements;
57
    }
58
}