Code Duplication    Length = 25-25 lines in 4 locations

src/Model/Payment/PaymentCollection.php 1 location

@@ 17-41 (lines=25) @@
14
 * @method Payment current()
15
 * @method Payment getAt($offset)
16
 */
17
class PaymentCollection extends Collection
18
{
19
    const ID = 'id';
20
    protected $type = '\Commercetools\Core\Model\Payment\Payment';
21
22
23
    protected function indexRow($offset, $row)
24
    {
25
        if ($row instanceof Payment) {
26
            $id = $row->getId();
27
        } else {
28
            $id = isset($row[static::ID]) ? $row[static::ID] : null;
29
        }
30
        $this->addToIndex(static::ID, $offset, $id);
31
    }
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

src/Model/Payment/TransactionCollection.php 1 location

@@ 17-41 (lines=25) @@
14
 * @method Transaction current()
15
 * @method Transaction getAt($offset)
16
 */
17
class TransactionCollection extends Collection
18
{
19
    const INTERACTION_ID = 'interactionId';
20
    protected $type = '\Commercetools\Core\Model\Payment\Transaction';
21
22
23
    protected function indexRow($offset, $row)
24
    {
25
        if ($row instanceof Transaction) {
26
            $id = $row->getInteractionId();
27
        } else {
28
            $id = isset($row[static::INTERACTION_ID]) ? $row[static::INTERACTION_ID] : null;
29
        }
30
        $this->addToIndex(static::INTERACTION_ID, $offset, $id);
31
    }
32
33
    /**
34
     * @param $id
35
     * @return Payment
36
     */
37
    public function getByInteractionId($id)
38
    {
39
        return $this->getBy(static::INTERACTION_ID, $id);
40
    }
41
}
42

src/Model/Common/AddressCollection.php 1 location

@@ 15-39 (lines=25) @@
12
 * @method AddressCollection add(Address $element)
13
 * @method Address getAt($offset)
14
 */
15
class AddressCollection extends Collection
16
{
17
    const ID = 'id';
18
19
    protected $type = '\Commercetools\Core\Model\Common\Address';
20
21
    protected function indexRow($offset, $row)
22
    {
23
        if ($row instanceof Address) {
24
            $name = $row->getId();
25
        } else {
26
            $name = $row[static::ID];
27
        }
28
        $this->addToIndex(static::ID, $offset, $name);
29
    }
30
31
    /**
32
     * @param $id
33
     * @return Address|null
34
     */
35
    public function getById($id = null)
36
    {
37
        return $this->getBy(static::ID, $id);
38
    }
39
}
40

src/Error/ErrorContainer.php 1 location

@@ 17-41 (lines=25) @@
14
 * @method ApiError current()
15
 * @method ApiError getAt($offset)
16
 */
17
class ErrorContainer extends Collection
18
{
19
    const CODE = 'code';
20
21
    protected $type = '\Commercetools\Core\Error\ApiError';
22
23
    protected function indexRow($offset, $row)
24
    {
25
        if ($row instanceof ApiError) {
26
            $id = $row->getCode();
27
        } else {
28
            $id = $row[static::CODE];
29
        }
30
        $this->addToIndex(static::CODE, $offset, $id);
31
    }
32
33
    /**
34
     * @param $code
35
     * @return ApiError
36
     */
37
    public function getByCode($code)
38
    {
39
        return $this->getBy(static::CODE, $code);
40
    }
41
}
42