Job::appendValueToBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
4
namespace DelayQueue;
5
6
use JsonSerializable;
7
8
/**
9
 * Job实体
10
 */
11
class Job implements JsonSerializable
12
{
13
    /**
14
     * @var string 队列名称
15
     */
16
    public $topic;
17
18
    /**
19
     * @var string Job唯一标识
20
     */
21
    public $id;
22
23
    /**
24
     * @var int 延迟时间, 单位秒
25
     */
26
    public $delay;
27
28
    /**
29
     * @var int 超时时间, 单位秒
30
     */
31
    public $ttr;
32
33
    /**
34
     * @var array Job内容
35
     */
36
    public $body;
37
38
    /**
39
     * @return string
40
     */
41
    public function getTopic()
42
    {
43
        return $this->topic;
44
    }
45
46
    /**
47
     * @param string $topic
48
     */
49
    public function setTopic($topic)
50
    {
51
        $this->topic = $topic;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getId()
58
    {
59
        return $this->id;
60
    }
61
62
    /**
63
     * @param string $id
64
     */
65
    public function setId($id)
66
    {
67
        $this->id = $id;
68
    }
69
70
    /**
71
     * @return int
72
     */
73
    public function getDelay()
74
    {
75
        return $this->delay;
76
    }
77
78
    /**
79
     * @param int $delay
80
     */
81
    public function setDelay($delay)
82
    {
83
        $this->delay = $delay;
84
    }
85
86
    /**
87
     * @return int
88
     */
89
    public function getTtr()
90
    {
91
        return $this->ttr;
92
    }
93
94
    /**
95
     * @param int $ttr
96
     */
97
    public function setTtr($ttr)
98
    {
99
        $this->ttr = $ttr;
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function getBody()
106
    {
107
        return $this->body;
108
    }
109
110
    /**
111
     * @param array $body
112
     */
113
    public function setBody(array $body)
114
    {
115
        $this->body = $body;
116
    }
117
118
    /**
119
     * @param string $key
120
     * @param mixed $value
121
     */
122
    public function appendValueToBody($key, $value)
123
    {
124
        $this->body[$key] = $value;
125
    }
126
127
    /**
128
     * @return array
129
     */
130
    public function toArray()
131
    {
132
        $arr = (array) $this;
133
        $arr['body'] = json_encode($arr['body']);
134
135
        return $arr;
136
    }
137
138
    /**
139
     * @return array
140
     */
141
    public function jsonSerialize()
142
    {
143
        return $this->toArray();
144
    }
145
}