Completed
Push — develop ( c6f9f9...59e20d )
by Jens
09:32
created

EnumCollection::indexRow()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
cc 2
eloc 6
nc 2
nop 2
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#plain-enum-value
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 = '\Commercetools\Core\Model\Common\Enum';
21
22 3
    protected function indexRow($offset, $row)
23
    {
24 3
        if ($row instanceof Enum) {
25 1
            $key = $row->getKey();
26
        } else {
27 2
            $key = $row[static::KEY];
28
        }
29 3
        $this->addToIndex(static::KEY, $offset, $key);
30 3
    }
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