Completed
Push — develop ( c6f9f9...59e20d )
by Jens
09:32
created

ShippingMethodCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 32
ccs 9
cts 11
cp 0.8182
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B indexRow() 0 16 6
A getByName() 0 4 1
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\ShippingMethod;
7
8
use Commercetools\Core\Model\Common\Collection;
9
10
/**
11
 * @package Commercetools\Core\Model\ShippingMethod
12
 * @link https://dev.commercetools.com/http-api-projects-shippingMethods.html#shipping-method
13
 * @method ShippingMethod current()
14
 * @method ShippingMethodCollection add(ShippingMethod $element)
15
 * @method ShippingMethod getAt($offset)
16
 */
17
class ShippingMethodCollection extends Collection
18
{
19
    const NAME = 'name';
20
21
    protected $type = '\Commercetools\Core\Model\ShippingMethod\ShippingMethod';
22
23 4
    protected function indexRow($offset, $row)
24
    {
25 4
        if ($row instanceof ShippingMethod) {
26
            $name = $row->getName();
27
            $id = $row->getId();
28
        } else {
29 4
            $name = isset($row[static::NAME]) ? $row[static::NAME] : null;
30 4
            $id = isset($row[static::ID]) ? $row[static::ID] : null;
31
        }
32 4
        if (!empty($name)) {
33 1
            $this->addToIndex(static::NAME, $offset, $name);
34
        }
35 4
        if (!empty($id)) {
36 1
            $this->addToIndex(static::ID, $offset, $id);
37
        }
38 4
    }
39
40
    /**
41
     * @param $name
42
     * @return ShippingMethod
43
     */
44
    public function getByName($name)
45
    {
46
        return $this->getBy(static::NAME, $name);
47
    }
48
}
49