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

LocalizedEnumCollection::getByKey()   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

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
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\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