Test Failed
Branch master (62528d)
by Zangra
14:14 queued 12:04
created

Barcode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Bpost\BpostApiClient\Bpost\Label;
5
6
use SimpleXMLElement;
7
8
/**
9
 * Class Barcode
10
 */
11
class Barcode
12
{
13
    public function __construct(
14
        private ?string $barcode = null,
15
        private ?string $reference = null,
16
    ) {}
17
18
    public function setBarcode(?string $barcode): void
19
    {
20
        $this->barcode = $barcode;
21
    }
22
23
    public function getBarcode(): ?string
24
    {
25
        return $this->barcode;
26
    }
27
28
    public function setReference(?string $reference): void
29
    {
30
        $this->reference = $reference;
31
    }
32
33
    public function getReference(): ?string
34
    {
35
        return $this->reference;
36
    }
37
38
    public static function createFromXML(SimpleXMLElement $xml): self
39
    {
40
        $self = new self();
41
42
        if (isset($xml->barcode) && (string)$xml->barcode !== '') {
43
            $self->setBarcode((string)$xml->barcode);
44
        }
45
        if (isset($xml->reference) && (string)$xml->reference !== '') {
46
            $self->setReference((string)$xml->reference);
47
        }
48
49
        return $self;
50
    }
51
}
52
53