1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2014 Underground Elephant |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
* |
18
|
|
|
* @package qpush-bundle |
19
|
|
|
* @copyright Underground Elephant 2014 |
20
|
|
|
* @license Apache License, Version 2.0 |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace Uecode\Bundle\QPushBundle\Message; |
24
|
|
|
|
25
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @author Keith Kirk <[email protected]> |
29
|
|
|
*/ |
30
|
|
View Code Duplication |
class Notification |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Notification Id |
34
|
|
|
* |
35
|
|
|
* @var int|string |
36
|
|
|
*/ |
37
|
|
|
protected $id; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Notification Body |
41
|
|
|
* |
42
|
|
|
* @var string|array |
43
|
|
|
*/ |
44
|
|
|
protected $body; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Notification Metadata |
48
|
|
|
* |
49
|
|
|
* @var ArrayCollection |
50
|
|
|
*/ |
51
|
|
|
protected $metadata; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Constructor. |
55
|
|
|
* |
56
|
|
|
* Sets the Notification Id, Notification Body, and any Notification Metadata |
57
|
|
|
* |
58
|
|
|
* @param int|string $id The Notification Id |
59
|
|
|
* @param string|array $body The Notification Message |
60
|
|
|
* @param array $metadata The Notification Metadata |
61
|
|
|
*/ |
62
|
15 |
|
public function __construct($id, $body, array $metadata) |
63
|
|
|
{ |
64
|
15 |
|
$this->id = $id; |
65
|
15 |
|
$this->metadata = new ArrayCollection($metadata); |
66
|
|
|
|
67
|
15 |
|
$message = is_string($body) ? json_decode($body, true) : $body; |
68
|
15 |
|
if (json_last_error() !== JSON_ERROR_NONE) { |
69
|
4 |
|
$message = $body; |
70
|
|
|
} |
71
|
|
|
|
72
|
15 |
|
$this->body = $message; |
73
|
15 |
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns the Notification Id |
77
|
|
|
* |
78
|
|
|
* @return int|string |
79
|
|
|
*/ |
80
|
4 |
|
public function getId() |
81
|
|
|
{ |
82
|
4 |
|
return $this->id; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns the Notification Body |
87
|
|
|
* |
88
|
|
|
* @return string|array |
89
|
|
|
*/ |
90
|
4 |
|
public function getBody() |
91
|
|
|
{ |
92
|
4 |
|
return $this->body; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the Notification Metadata |
97
|
|
|
* |
98
|
|
|
* @return ArrayCollection |
99
|
|
|
*/ |
100
|
5 |
|
public function getMetadata() |
101
|
|
|
{ |
102
|
5 |
|
return $this->metadata; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
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.