Completed
Push — master ( 18bfc7...82e0b5 )
by Jens
18:00 queued 05:19
created

Destination   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 32
Duplicated Lines 31.25 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 10
loc 32
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldDefinitions() 0 6 1
A destinationType() 0 8 2
A fromArray() 10 10 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Subscription;
7
8
use Commercetools\Core\Model\Common\JsonObject;
9
10
/**
11
 * @package Commercetools\Core\Model\Subscription
12
 *
13
 * @method string getType()
14
 * @method Destination setType(string $type = null)
15
 */
16
class Destination extends JsonObject
17
{
18
    const DESTINATION_SQS = 'SQS';
19
    const DESTINATION_IRON_MQ = 'IronMQ';
20
21
    public function fieldDefinitions()
22
    {
23
        return [
24
            'type' => [static::TYPE => 'string']
25
        ];
26
    }
27
28
    protected static function destinationType($typeId)
29
    {
30
        $types = [
31
            static::DESTINATION_SQS => '\Commercetools\Core\Model\Subscription\SQSDestination',
32
            static::DESTINATION_IRON_MQ => '\Commercetools\Core\Model\Subscription\IronMQDestination',
33
        ];
34
        return isset($types[$typeId]) ? $types[$typeId] : '\Commercetools\Core\Model\Subscription\Destination';
35
    }
36
37 View Code Duplication
    public static function fromArray(array $data, $context = null)
0 ignored issues
show
Duplication introduced by
This method 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...
38
    {
39
        if (get_called_class() == 'Commercetools\Core\Model\Subscription\Destination' && isset($data[static::TYPE])) {
40
            $className = static::destinationType($data[static::TYPE]);
41
            if (class_exists($className)) {
42
                return new $className($data, $context);
43
            }
44
        }
45
        return new static($data, $context);
46
    }
47
}
48