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

ShippingMethodCollection::getById()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
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