Passed
Push — master ( 18b32f...fa2b73 )
by Jens
08:15
created

AddressCollection::indexRow()   A

Complexity

Conditions 5
Paths 6

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 13
ccs 11
cts 11
cp 1
rs 9.6111
c 0
b 0
f 0
cc 5
nc 6
nop 2
crap 5
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-types.html#address
11
 * @method Address current()
12
 * @method AddressCollection add(Address $element)
13
 * @method Address getAt($offset)
14
 * @method Address getById($offset)
15
 */
16
class AddressCollection extends Collection
17
{
18
    const KEY = 'key';
19
20
    protected $type = Address::class;
21
22 110
    protected function indexRow($offset, $row)
23
    {
24 110
        $id = null;
25 110
        $key = null;
26 110
        if ($row instanceof Address) {
27 102
            $id = $row->getId();
28 102
            $key = $row->getKey();
29 67
        } elseif (is_array($row)) {
30 67
            $id = isset($row[static::ID]) ? $row[static::ID] : null;
31 67
            $key = isset($row[static::KEY]) ? $row[static::KEY] : null;
32
        }
33 110
        $this->addToIndex(static::ID, $offset, $id);
34 110
        $this->addToIndex(static::KEY, $offset, $key);
35 110
    }
36
37
    /**
38
     * @param $key
39
     * @return Address|null
40
     */
41
    public function getByKey($key)
42
    {
43
        return $this->getBy(static::KEY, $key);
44
    }
45
}
46