Response::addShippingMethod()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 9.6666
1
<?php namespace SimpleUPS\Rates;
2
3
class Response extends \SimpleUPS\Api\Response
4
{
5
    private
6
        /* @var ShippingMethod[] $shippingMethods */
7
        $shippingMethods;
8
9
    /**
10
     * @internal
11
     *
12
     * @param ShippingMethod $shippingMethod
13
     *
14
     * @return Response
15
     */
16
    public function addShippingMethod(ShippingMethod $shippingMethod)
17
    {
18
        if ($this->shippingMethods === null) {
19
            $this->shippingMethods = array();
20
        }
21
22
        $this->shippingMethods[] = $shippingMethod;
23
        return $this;
24
    }
25
26
    /**
27
     * @return ShippingMethod[]|null
28
     */
29
    public function getShippingMethods()
30
    {
31
        return $this->shippingMethods;
32
    }
33
34
    /**
35
     * @param \SimpleXMLElement $xml
36
     *
37
     * @return Response
38
     */
39
    public function fromXml(\SimpleXMLElement $xml)
40
    {
41
        foreach ($xml->RatedShipment as $ratedShipment) {
42
            $this->addShippingMethod(ShippingMethod::fromXml($ratedShipment));
43
        }
44
45
        return $this;
46
    }
47
}