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

EnumCollection::getByKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 1
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