Details   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 78
rs 10
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getShippingCost() 0 3 1
A setShippingCost() 0 5 1
A __construct() 0 3 1
A getProducts() 0 3 1
A addProduct() 0 5 1
A import() 0 11 6
1
<?php
2
3
namespace Pagantis\OrdersApiClient\Model\Order\ShoppingCart;
4
5
use Pagantis\OrdersApiClient\Model\AbstractModel;
6
use Pagantis\OrdersApiClient\Model\Order\ShoppingCart\Details\Product;
7
8
/**
9
 * Class Details
10
 * @package Pagantis\OrdersApiClient\Model\Order\ShoppingCart
11
 */
12
class Details extends AbstractModel
13
{
14
    /**
15
     * @var Product[]
16
     */
17
    protected $products;
18
19
    /**
20
     * @var int $shipping_cost Shipping cost for the order
21
     */
22
    protected $shippingCost;
23
24
    /**
25
     * Details constructor.
26
     */
27
    public function __construct()
28
    {
29
        $this->products = array();
30
    }
31
32
    /**
33
     * @return Product[]
34
     */
35
    public function getProducts()
36
    {
37
        return $this->products;
38
    }
39
40
    /**
41
     * @param Product $product
42
     *
43
     * @return Details
44
     */
45
    public function addProduct(Product $product)
46
    {
47
        $this->products[] = $product;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return int
54
     */
55
    public function getShippingCost()
56
    {
57
        return $this->shippingCost;
58
    }
59
60
    /**
61
     * @param $shippingCost
62
     *
63
     * @return $this
64
     */
65
    public function setShippingCost($shippingCost)
66
    {
67
        $this->shippingCost = $shippingCost;
68
69
        return $this;
70
    }
71
72
    /**
73
     * Overwrite import to fill products correctly
74
     *
75
     * @param \stdClass $object
76
     *
77
     * @throws \Exception
78
     */
79
    public function import($object)
80
    {
81
        parent::import($object);
82
        $properties = get_object_vars($object);
83
        foreach ($properties as $key => $value) {
84
            if (is_array($value) && is_array($this->{$key}) && $key == 'products') {
85
                $this->products = array();
86
                foreach ($value as $product) {
87
                    $productObject = new Product();
88
                    $productObject->import($product);
89
                    $this->addProduct($productObject);
90
                }
91
            }
92
        }
93
    }
94
}
95