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

TransactionCollection::getByInteractionId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
crap 2
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