Completed
Push — master ( 9be2e3...3a8fde )
by Gaël
14:21
created

CartResource   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A addItem() 0 3 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(array_merge(
31
            $fields,
32
            [
33
                self::ITEMS_KEY => [],
34
            ]
35
        ));
36
    }
37
38
    /**
39
     * @param CartItemResource $item
40
     */
41
    public function addItem(CartItemResource $item): void
42
    {
43
        array_push($this->parameters[self::ITEMS_KEY], $item->getParameters());
44
    }
45
}
46