CartResource   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 37
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addItem() 0 7 1
1
<?php
2
3
4
namespace DansMaCulotte\Monetico\Resources;
5
6
use DansMaCulotte\Monetico\Exceptions\Exception;
7
8
class CartResource extends Ressource
9
{
10
    const ITEMS_KEY = 'shoppingCartItems';
11
12
    /** @var array */
13
    protected $keys = [
14
        'giftCardAmount',
15
        'giftCardCount',
16
        'giftCardCurrency',
17
        'preOrderDate',
18
        'preorderIndicator',
19
        'shoppingCartItems',
20
    ];
21
22
    /**
23
     * Client constructor.
24
     *
25
     * @param array $fields
26
     * @throws Exception
27
     */
28
    public function __construct(array $fields = [])
29
    {
30
        parent::__construct($fields);
31
        $this->setParameter(self::ITEMS_KEY, []);
32
    }
33
34
    /**
35
     * @param CartItemResource $item
36
     * @throws Exception
37
     */
38
    public function addItem(CartItemResource $item): void
39
    {
40
        $items = $this->getParameter(self::ITEMS_KEY);
41
42
        $items[] = $item->getParameters();
43
44
        $this->setParameter(self::ITEMS_KEY, $items);
45
    }
46
}
47