Passed
Push — master ( 0d508a...6e2a06 )
by Jens
16:22 queued 10s
created

OrderEditResult   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 7
eloc 15
dl 0
loc 37
c 0
b 0
f 0
ccs 13
cts 14
cp 0.9286
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 9 4
A fieldDefinitions() 0 4 1
A resultType() 0 10 2
1
<?php
2
/**
3
 *
4
 */
5
6
namespace Commercetools\Core\Model\OrderEdit;
7
8
use Commercetools\Core\Model\Common\Context;
9
use Commercetools\Core\Model\Common\JsonObject;
10
11
/**
12
 * @package Commercetools\Core\Model\OrderEdit
13
 *
14
 * @method string getType()
15
 * @method OrderEditResult setType(string $type = null)
16
 */
17
class OrderEditResult extends JsonObject
18
{
19
    const ORDER_EDIT_RESULT_TYPE = '';
20
21 4
    public function fieldDefinitions()
22
    {
23
        return [
24 4
            'type' => [static::TYPE => 'string'],
25
        ];
26
    }
27
28
    /**
29
     * @param array $data
30
     * @param Context|callable $context
31
     * @return static
32
     */
33 49
    public static function fromArray(array $data, $context = null)
34
    {
35 49
        if (get_called_class() == OrderEditResult::class && isset($data['type'])) {
36 49
            $className = static::resultType($data['type']);
37 49
            if (class_exists($className)) {
38 49
                return new $className($data, $context);
39
            }
40
        }
41
        return new static($data, $context);
42
    }
43
44 49
    protected static function resultType($typeId)
45
    {
46
        $types = [
47 49
            OrderEditNotProcessed::ORDER_EDIT_RESULT_TYPE => OrderEditNotProcessed::class,
48 49
            OrderEditPreviewFailure::ORDER_EDIT_RESULT_TYPE => OrderEditPreviewFailure::class,
49 49
            OrderEditPreviewSuccess::ORDER_EDIT_RESULT_TYPE => OrderEditPreviewSuccess::class,
50 49
            OrderEditApplied::ORDER_EDIT_RESULT_TYPE => OrderEditApplied::class,
51
52
        ];
53 49
        return isset($types[$typeId]) ? $types[$typeId] : OrderEditResult::class;
54
    }
55
}
56