Completed
Push — develop ( 991012...b60d88 )
by Jens
08:17
created

PaymentCollection::indexRow()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 9
loc 9
ccs 5
cts 6
cp 0.8333
rs 9.6666
cc 3
eloc 6
nc 3
nop 2
crap 3.0416
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Payment;
7
8
use Commercetools\Core\Model\Common\Collection;
9
10
/**
11
 * @package Commercetools\Core\Model\Payment
12
 * @link https://dev.commercetools.com/http-api-projects-payments.html#payment
13
 * @method PaymentCollection add(Payment $element)
14
 * @method Payment current()
15
 * @method Payment getAt($offset)
16
 */
17 View Code Duplication
class PaymentCollection extends Collection
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    const ID = 'id';
20
    protected $type = '\Commercetools\Core\Model\Payment\Payment';
21
22
23 2
    protected function indexRow($offset, $row)
24
    {
25 2
        if ($row instanceof Payment) {
26
            $id = $row->getId();
27
        } else {
28 2
            $id = isset($row[static::ID]) ? $row[static::ID] : null;
29
        }
30 2
        $this->addToIndex(static::ID, $offset, $id);
31 2
    }
32
33
    /**
34
     * @param $id
35
     * @return Payment
36
     */
37
    public function getById($id)
38
    {
39
        return $this->getBy(static::ID, $id);
40
    }
41
}
42