Test Failed
Push — develop ( c17639...818a9c )
by Jens
09:56
created

OrderEditResult::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 2
c 1
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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
    public static function fromArray(array $data, $context = null)
34
    {
35
        if (get_called_class() == OrderEditResult::class && isset($data['type'])) {
36
            $className = static::resultType($data['type']);
37
            if (class_exists($className)) {
38
                return new $className($data, $context);
39
            }
40
        }
41
        return new static($data, $context);
42
    }
43
44
    protected static function resultType($typeId)
45
    {
46
        $types = [
47
            OrderEditNotProcessed::ORDER_EDIT_RESULT_TYPE => OrderEditNotProcessed::class,
48
            OrderEditPreviewFailure::ORDER_EDIT_RESULT_TYPE => OrderEditPreviewFailure::class,
49
            OrderEditPreviewSuccess::ORDER_EDIT_RESULT_TYPE => OrderEditPreviewSuccess::class,
50
            OrderEditApplied::ORDER_EDIT_RESULT_TYPE => OrderEditApplied::class,
51
52
        ];
53
        return isset($types[$typeId]) ? $types[$typeId] : OrderEditResult::class;
54
    }
55
}
56