Code Duplication    Length = 14-25 lines in 4 locations

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/ProductType/AttributeDefinitionCollection.php 1 location

@@ 17-41 (lines=25) @@
14
 * @method AttributeDefinitionCollection add(AttributeDefinition $element)
15
 * @method AttributeDefinition getAt($offset)
16
 */
17
class AttributeDefinitionCollection extends Collection
18
{
19
    protected $type = '\Commercetools\Core\Model\ProductType\AttributeDefinition';
20
21
    const NAME = 'name';
22
23
    protected function indexRow($offset, $row)
24
    {
25
        if ($row instanceof AttributeDefinition) {
26
            $name = $row->getName();
27
        } else {
28
            $name = $row[static::NAME];
29
        }
30
        $this->addToIndex(static::NAME, $offset, $name);
31
    }
32
33
    /**
34
     * @param $name
35
     * @return AttributeDefinition
36
     */
37
    public function getByName($name)
38
    {
39
        return $this->getBy(static::NAME, $name);
40
    }
41
}
42

src/Model/Product/ProductProjectionCollection.php 1 location

@@ 17-30 (lines=14) @@
14
 * @method ProductProjectionCollection add(ProductProjection $element)
15
 * @method ProductProjection getAt($offset)
16
 */
17
class ProductProjectionCollection extends Collection
18
{
19
    protected $type = '\Commercetools\Core\Model\Product\ProductProjection';
20
21
    protected function indexRow($offset, $row)
22
    {
23
        if ($row instanceof ProductProjection) {
24
            $id = $row->getId();
25
        } else {
26
            $id = isset($row[static::ID]) ? $row[static::ID]: null;
27
        }
28
        $this->addToIndex(static::ID, $offset, $id);
29
    }
30
}
31

src/Model/Common/AssetSourceCollection.php 1 location

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