Passed
Push — develop ( c0b367...899431 )
by Jens
07:13
created

EnumCollection::indexRow()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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