ProductConfiguration::addDeliveryMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Bpost\BpostApiClient\Bpost;
4
5
use SimpleXMLElement;
6
use Bpost\BpostApiClient\Bpost\ProductConfiguration\DeliveryMethod;
7
8
/**
9
 * Class ProductConfiguration
10
 * @package Bpost\BpostApiClient\Bpost
11
 */
12
class ProductConfiguration
13
{
14
15
    /** @var array DeliveryMethod[] */
16
    private $deliveryMethods = array();
17
18
    /**
19
     * @return DeliveryMethod[]
20
     */
21
    public function getDeliveryMethods()
22
    {
23
        return $this->deliveryMethods;
24
    }
25
26
    /**
27
     * @param DeliveryMethod $deliveryMethod
28
     */
29
    public function addDeliveryMethod(DeliveryMethod $deliveryMethod)
30
    {
31
        $this->deliveryMethods[] = $deliveryMethod;
32
    }
33
34
    /**
35
     * @param SimpleXMLElement $xml
36
     *
37
     * @return ProductConfiguration
38
     */
39
    public static function createFromXML(SimpleXMLElement $xml)
40
    {
41
        $productConfiguration = new self();
42
        $children = $xml->children();
43
44
        if (isset($children->deliveryMethod)) {
45
            foreach ($children->deliveryMethod as $deliveryMethodXml) {
46
                $productConfiguration->addDeliveryMethod(DeliveryMethod::createFromXML($deliveryMethodXml));
47
            }
48
        }
49
50
        return $productConfiguration;
51
    }
52
}
53