ItemBag::add()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 11
cts 11
cp 1
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
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 4
    public function add($item)
18
    {
19 4
        if ($item instanceof Item) {
20 1
            $this->items[] = $item;
21 3
        } elseif ($item instanceof ItemInterface) {
22 1
            $this->items[] = new Item(array(
23 1
                'name'        => $item->getName(),
24 1
                'description' => $item->getDescription(),
25 1
                'quantity'    => $item->getQuantity(),
26 1
                'price'       => $item->getPrice(),
27
            ));
28
        } else {
29 2
            $this->items[] = new Item($item);
30
        }
31 4
    }
32
}
33