Completed
Push — master ( 4b89b9...dd9abc )
by Jens
10:35
created

LocalizedEnumCollection::indexRow()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 5
cts 6
cp 0.8333
rs 9.6666
cc 2
eloc 6
nc 2
nop 2
crap 2.0185
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Common;
7
8
/**
9
 * @package Commercetools\Core\Model\Common
10
 * @link https://dev.commercetools.com/http-api-projects-products.html#product-variant-attribute
11
 * @link https://dev.commercetools.com/http-api-projects-productTypes.html#localized-enum-value
12
 * @method LocalizedEnum current()
13
 * @method LocalizedEnumCollection add(LocalizedEnum $element)
14
 * @method LocalizedEnum getAt($offset)
15
 */
16
class LocalizedEnumCollection extends Collection
17
{
18
    const KEY = 'key';
19
20
    protected $type = '\Commercetools\Core\Model\Common\LocalizedEnum';
21
22 2
    protected function indexRow($offset, $row)
23
    {
24 2
        if ($row instanceof Enum) {
25
            $key = $row->getKey();
26
        } else {
27 2
            $key = $row[static::KEY];
28
        }
29 2
        $this->addToIndex(static::KEY, $offset, $key);
30 2
    }
31
32
    /**
33
     * @param $key
34
     * @return static
35
     */
36
    public function getByKey($key)
37
    {
38
        return $this->getBy(static::KEY, $key);
39
    }
40
}
41