Completed
Push — develop ( 991012...b60d88 )
by Jens
08:17
created

ShippingMethodCollection::indexRow()   B

Complexity

Conditions 6
Paths 20

Size

Total Lines 16
Code Lines 11

Duplication

Lines 7
Ratio 43.75 %

Code Coverage

Tests 9
CRAP Score 6.2163
Metric Value
dl 7
loc 16
ccs 9
cts 11
cp 0.8182
rs 8.8571
cc 6
eloc 11
nc 20
nop 2
crap 6.2163
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