Completed
Push — master ( 4b89b9...dd9abc )
by Jens
10:35
created

Message::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 19
ccs 11
cts 11
cp 1
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
crap 1
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 3 View Code Duplication
    public function __construct(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...
43
    {
44 3
        parent::__construct($data, $context);
45 3
        $type = static::MESSAGE_TYPE;
46 3
        if (!empty($type)) {
47
            $this->setType(static::MESSAGE_TYPE);
48
        }
49 3
    }
50
51 2
    public function fieldDefinitions()
52
    {
53
        return [
54 2
            'id' => [static::TYPE => 'string'],
55 2
            'version' => [static::TYPE => 'int'],
56
            'createdAt' => [
57 2
                static::TYPE => '\DateTime',
58 2
                static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
59
            ],
60
            'lastModifiedAt' => [
61 2
                static::TYPE => '\DateTime',
62 2
                static::DECORATOR => '\Commercetools\Core\Model\Common\DateTimeDecorator'
63
            ],
64 2
            'sequenceNumber' => [static::TYPE => 'int'],
65 2
            'resource' => [static::TYPE => '\Commercetools\Core\Model\Common\Reference'],
66 2
            'resourceVersion' => [static::TYPE => 'int'],
67 2
            'type' => [static::TYPE => 'string'],
68
        ];
69
    }
70
71
    /**
72
     * @param array $data
73
     * @param Context|callable $context
74
     * @return static
75
     */
76 1
    public static function fromArray(array $data, $context = null)
77
    {
78 1
        if (isset($data['type'])) {
79
            $className = '\Commercetools\Core\Model\Message\\' . ucfirst($data['type']) . 'Message';
80
            if (class_exists($className)) {
81
                return new $className($data, $context);
82
            }
83
        }
84 1
        return new static($data, $context);
85
    }
86
}
87