Passed
Push — develop ( e75002...49ff19 )
by Jens
08:50
created

Destination   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 13.33%

Importance

Changes 0
Metric Value
wmc 7
eloc 20
dl 0
loc 36
ccs 2
cts 15
cp 0.1333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 9 4
A destinationType() 0 10 2
A fieldDefinitions() 0 4 1
1
<?php
2
/**
3
 * @author @jenschude <[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
    const DESTINATION_SNS = 'SNS';
21
    const DESTINATION_AZURE_SERVICE_BUS = 'AzureServiceBus';
22
    const DESTINATION_GOOGLE_CLOUD_PUB_SUB = 'GoogleCloudPubSub';
23
24 1
    public function fieldDefinitions()
25
    {
26
        return [
27 1
            'type' => [static::TYPE => 'string']
28
        ];
29
    }
30
31
    protected static function destinationType($typeId)
32
    {
33
        $types = [
34
            static::DESTINATION_SQS => SQSDestination::class,
35
            static::DESTINATION_IRON_MQ => IronMQDestination::class,
36
            static::DESTINATION_SNS => SNSDestination::class,
37
            static::DESTINATION_AZURE_SERVICE_BUS => AzureServiceBusDestination::class,
38
            static::DESTINATION_GOOGLE_CLOUD_PUB_SUB => GoogleCloudPubSubDestination::class,
39
        ];
40
        return isset($types[$typeId]) ? $types[$typeId] : Destination::class;
41
    }
42
43
    public static function fromArray(array $data, $context = null)
44
    {
45
        if (get_called_class() == Destination::class && isset($data[static::TYPE])) {
46
            $className = static::destinationType($data[static::TYPE]);
47
            if (class_exists($className)) {
48
                return new $className($data, $context);
49
            }
50
        }
51
        return new static($data, $context);
52
    }
53
}
54