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

EnumCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 23
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexRow() 0 8 2
A getByKey() 0 3 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