Passed
Branch php-scrutinizer (0ac9d8)
by Jens
09:19
created

TransactionCollection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 62.5%

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 23
ccs 5
cts 8
cp 0.625
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexRow() 0 8 3
A getByInteractionId() 0 3 1
1
<?php
2
/**
3
 * @author @jenschude <[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://docs.commercetools.com/http-api-projects-payments.html#transaction
13
 * @method TransactionCollection add(Transaction $element)
14
 * @method Transaction current()
15
 * @method Transaction getAt($offset)
16
 * @method Transaction getById($offset)
17
 */
18
class TransactionCollection extends Collection
19
{
20
    const INTERACTION_ID = 'interactionId';
21
    protected $type = Transaction::class;
22
23
24 1
    protected function indexRow($offset, $row)
25
    {
26 1
        if ($row instanceof Transaction) {
27
            $id = $row->getInteractionId();
28
        } else {
29 1
            $id = isset($row[static::INTERACTION_ID]) ? $row[static::INTERACTION_ID] : null;
30
        }
31 1
        $this->addToIndex(static::INTERACTION_ID, $offset, $id);
32 1
    }
33
34
    /**
35
     * @param $id
36
     * @return Payment
37
     */
38
    public function getByInteractionId($id)
39
    {
40
        return $this->getBy(static::INTERACTION_ID, $id);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getBy(static::INTERACTION_ID, $id) also could return the type Commercetools\Core\Model\Payment\Transaction which is incompatible with the documented return type Commercetools\Core\Model\Payment\Payment.
Loading history...
41
    }
42
}
43