Test Failed
Push — develop ( 602303...60e207 )
by Jens
08:55
created

MessageDelivery::fieldDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 22
ccs 14
cts 14
cp 1
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * @author @jenschude <[email protected]>
4
 */
5
6
namespace Commercetools\Core\Model\Subscription;
7
8
use Commercetools\Core\Model\Common\Reference;
9
use Commercetools\Core\Model\Common\DateTimeDecorator;
10
use Commercetools\Core\Model\Message\Message;
11
use DateTime;
12
13
/**
14
 * @package Commercetools\Core\Model\Subscription
15
 * @method string getProjectKey()
16
 * @method MessageDelivery setProjectKey(string $projectKey = null)
17
 * @method string getNotificationType()
18
 * @method MessageDelivery setNotificationType(string $notificationType = null)
19
 * @method Reference getResource()
20
 * @method MessageDelivery setResource(Reference $resource = null)
21
 * @method string getId()
22
 * @method MessageDelivery setId(string $id = null)
23
 * @method int getVersion()
24
 * @method MessageDelivery setVersion(int $version = null)
25
 * @method int getSequenceNumber()
26
 * @method MessageDelivery setSequenceNumber(int $sequenceNumber = null)
27
 * @method int getResourceVersion()
28
 * @method MessageDelivery setResourceVersion(int $resourceVersion = null)
29
 * @method DateTimeDecorator getCreatedAt()
30
 * @method MessageDelivery setCreatedAt(DateTime $createdAt = null)
31
 * @method DateTimeDecorator getLastModifiedAt()
32
 * @method MessageDelivery setLastModifiedAt(DateTime $lastModifiedAt = null)
33
 * @method PayloadNotIncluded getPayloadNotIncluded()
34
 * @method MessageDelivery setPayloadNotIncluded(PayloadNotIncluded $payloadNotIncluded = null)
35
 */
36
class MessageDelivery extends Delivery
37
{
38 1
    public function fieldDefinitions()
39
    {
40 1
        $definition = parent::fieldDefinitions();
41 1
        $definition = array_merge(
42 1
            $definition,
43
            [
44 1
                'id' => [static::TYPE => 'string'],
45 1
                'version' => [static::TYPE => 'int'],
46 1
                'sequenceNumber' => [static::TYPE => 'int'],
47 1
                'resourceVersion' => [static::TYPE => 'int'],
48
                'createdAt' => [
49 1
                    static::TYPE => DateTime::class,
50 1
                    static::DECORATOR => DateTimeDecorator::class
51
                ],
52
                'lastModifiedAt' => [
53 1
                    static::TYPE => DateTime::class,
54 1
                    static::DECORATOR => DateTimeDecorator::class
55
                ],
56 1
                'payloadNotIncluded' => [static::TYPE => PayloadNotIncluded::class],
57
            ]
58
        );
59 1
        return $definition;
60
    }
61
62
    /**
63
     * @return Message
64
     */
65 2
    public function getMessage()
66
    {
67 2
        return Message::fromArray($this->rawData);
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getMessageType()
74
    {
75
        if (is_null($this->getPayloadNotIncluded())) {
76
            return $this->getMessage()->getType();
77
        }
78
        return $this->getPayloadNotIncluded()->getPayloadType();
79
    }
80
}
81