Completed
Push — master ( de0635...69f45f )
by Leith
17:25
created

ItemBag::add()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
1
<?php
2
3
namespace Omnipay\CapitaPay360;
4
5
use Omnipay\Common\ItemBag as BaseItemBag;
6
use Omnipay\Common\ItemInterface;
7
use Omnipay\CapitaPay360\Item;
8
9
/**
10
 * Capita Pay360 collection of sale line items
11
 */
12
class ItemBag extends BaseItemBag
13
{
14
    /**
15
     * Override {@see Omnipay\Common\ItemBag::add()} to use custom {@see Omnipay\CapitaPay360\Item} class
16
     */
17
    public function add($item)
18
    {
19
        if ($item instanceof Item) {
20
            $this->items[] = $item;
21
        } else if ($item instanceof ItemInterface) {
22
            $this->items[] = new Item([
23
                'name'        => $item->getName(),
24
                'description' => $item->getDescription(),
25
                'quantity'    => $item->getQuantity(),
26
                'price'       => $item->getPrice(),
27
            ]);
28
        } else {
29
            $this->items[] = new Item($item);
30
        }
31
    }
32
}
33