Passed
Push — master ( abc4fa...7f4e81 )
by
unknown
04:26
created

Barcode::createFromXML()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 8.8571
ccs 9
cts 9
cp 1
cc 5
eloc 7
nc 4
nop 1
crap 5
1
<?php
2
3
namespace Bpost\BpostApiClient\Bpost\Label;
4
5
use Bpost\BpostApiClient\Exception\BpostLogicException\BpostInvalidValueException;
6
7
/**
8
 * Class Barcode
9
 * @package Bpost\BpostApiClient\Bpost\Label
10
 */
11
class Barcode
12
{
13
14
    /**
15
     * @var string
16
     */
17
    private $barcode;
18
19
    /**
20
     * @var string
21
     */
22
    private $reference;
23
24
    /**
25
     * @param string $barcode
26
     */
27 3
    public function setBarcode($barcode)
28
    {
29 3
        $this->barcode = (string)$barcode;
30 3
    }
31
32
    /**
33
     * @return string
34
     */
35 3
    public function getBarcode()
36
    {
37 3
        return $this->barcode;
38
    }
39
40
    /**
41
     * @param string $reference
42
     */
43 3
    public function setReference($reference)
44
    {
45 3
        $this->reference = $reference;
46 3
    }
47
48
    /**
49
     * @return string
50
     */
51 1
    public function getReference()
52
    {
53 1
        return $this->reference;
54
    }
55
56
    /**
57
     * @param \SimpleXMLElement $xml
58
     *
59
     * @return self
60
     */
61 3
    public static function createFromXML(\SimpleXMLElement $xml)
62
    {
63 3
        $self = new self();
64 3
        if (isset($xml->barcode) && $xml->barcode != '') {
65 3
            $self->setBarcode((string)$xml->barcode);
66 3
        }
67 3
        if (isset($xml->reference) && $xml->reference != '') {
68 3
            $self->setReference((string)$xml->reference);
69 3
        }
70
71 3
        return $self;
72
    }
73
}
74