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

Barcode   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
eloc 11
c 2
b 0
f 0
dl 0
loc 39
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setReference() 0 3 1
A createFromXML() 0 12 5
A setBarcode() 0 3 1
A __construct() 0 4 1
A getReference() 0 3 1
A getBarcode() 0 3 1
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