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

Message   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 53
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldDefinitions() 0 19 1
A __construct() 0 8 2
A fromArray() 0 10 3
1
<?php
2
/**
3
 * @author @jayS-de <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Message;
7
8
use Commercetools\Core\Model\Common\Context;
9
use Commercetools\Core\Model\Common\JsonObject;
10
use Commercetools\Core\Model\Common\Reference;
11
use Commercetools\Core\Model\Common\DateTimeDecorator;
12
use Commercetools\Core\Model\Common\Resource;
13
14
/**
15
 * @package Commercetools\Core\Model\Message
16
 * @link https://dev.commercetools.com/http-api-projects-messages.html#message
17
 * @method string getId()
18
 * @method Message setId(string $id = null)
19
 * @method DateTimeDecorator getCreatedAt()
20
 * @method Message setCreatedAt(\DateTime $createdAt = null)
21
 * @method int getSequenceNumber()
22
 * @method Message setSequenceNumber(int $sequenceNumber = null)
23
 * @method Reference getResource()
24
 * @method Message setResource(Reference $resource = null)
25
 * @method int getResourceVersion()
26
 * @method Message setResourceVersion(int $resourceVersion = null)
27
 * @method string getType()
28
 * @method Message setType(string $type = null)
29
 * @method int getVersion()
30
 * @method Message setVersion(int $version = null)
31
 * @method DateTimeDecorator getLastModifiedAt()
32
 * @method Message setLastModifiedAt(\DateTime $lastModifiedAt = null)
33
 */
34
class Message extends Resource
35
{
36
    const MESSAGE_TYPE = '';
37
38
    /**
39
     * @param array $data
40
     * @param Context|callable $context
41
     */
42 4
    public function __construct(array $data = [], $context = null)
43
    {
44 4
        parent::__construct($data, $context);
45 4
        $type = static::MESSAGE_TYPE;
46 4
        if (!empty($type)) {
47 1
            $this->setType(static::MESSAGE_TYPE);
48
        }
49 4
    }
50
51 3
    public function fieldDefinitions()
52
    {
53
        return [
54 3
            'id' => [static::TYPE => 'string'],
55 3
            'version' => [static::TYPE => 'int'],
56
            'createdAt' => [
57 3
                static::TYPE => '\DateTime',
58 3
                static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
59
            ],
60
            'lastModifiedAt' => [
61 3
                static::TYPE => '\DateTime',
62 3
                static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
63
            ],
64 3
            'sequenceNumber' => [static::TYPE => 'int'],
65 3
            'resource' => [static::TYPE => '\Commercetools\Core\Model\Common\Reference'],
66 3
            'resourceVersion' => [static::TYPE => 'int'],
67 3
            'type' => [static::TYPE => 'string'],
68
        ];
69
    }
70
71
    /**
72
     * @param array $data
73
     * @param Context|callable $context
74
     * @return static
75
     */
76 2
    public static function fromArray(array $data, $context = null)
77
    {
78 2
        if (isset($data['type'])) {
79 1
            $className = '\Commercetools\Core\Model\Message\\' . ucfirst($data['type']) . 'Message';
80 1
            if (class_exists($className)) {
81 1
                return new $className($data, $context);
82
            }
83
        }
84 1
        return new static($data, $context);
85
    }
86
}
87