Completed
Push — develop ( 991012...b60d88 )
by Jens
08:17
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
    const ID = 'id';
21
22
    protected $type = '\Commercetools\Core\Model\ShippingMethod\ShippingMethod';
23
24 4
    protected function indexRow($offset, $row)
25
    {
26 4 View Code Duplication
        if ($row instanceof ShippingMethod) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
27
            $name = $row->getName();
28
            $id = $row->getId();
29
        } else {
30 4
            $name = isset($row[static::NAME]) ? $row[static::NAME] : null;
31 4
            $id = isset($row[static::ID]) ? $row[static::ID] : null;
32
        }
33 4
        if (!empty($name)) {
34 1
            $this->addToIndex(static::NAME, $offset, $name);
35
        }
36 4
        if (!empty($id)) {
37 1
            $this->addToIndex(static::ID, $offset, $id);
38
        }
39 4
    }
40
41
    /**
42
     * @param $id
43
     * @return ShippingMethod
44
     */
45
    public function getById($id)
46
    {
47
        return $this->getBy(static::ID, $id);
48
    }
49
50
    /**
51
     * @param $name
52
     * @return ShippingMethod
53
     */
54
    public function getByName($name)
55
    {
56
        return $this->getBy(static::NAME, $name);
57
    }
58
}
59