|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Openpp\NotificationHubsRest\Notification; |
|
4
|
|
|
|
|
5
|
|
|
abstract class AbstractNotification implements NotificationInterface |
|
6
|
|
|
{ |
|
7
|
|
|
const SCHEDULE_TIME_FORMAT = 'Y-m-d\TH:i:s'; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* @var tring|array |
|
11
|
|
|
*/ |
|
12
|
|
|
protected $alert; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var array |
|
16
|
|
|
*/ |
|
17
|
|
|
protected $options; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @var string|string[] |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $tagsOrTagExpression; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var \DateTime |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $scheduleTime; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Initializes a new Notification. |
|
31
|
|
|
* |
|
32
|
|
|
* @param string|string[] $alert |
|
33
|
|
|
* @param array $options |
|
34
|
|
|
* @param string|string[] $tagsOrTagExpression |
|
35
|
|
|
* @param \DateTime $scheduleTime |
|
36
|
|
|
* |
|
37
|
|
|
* @throws \RuntimeException |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct($alert, $options = [], $tagsOrTagExpression = '', \DateTime $scheduleTime = null) |
|
40
|
|
|
{ |
|
41
|
|
|
$this->alert = $alert; |
|
|
|
|
|
|
42
|
|
|
$this->options = $options; |
|
43
|
|
|
$this->tagsOrTagExpression = $tagsOrTagExpression; |
|
44
|
|
|
$this->scheduleTime = $scheduleTime; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getHeaders() |
|
51
|
|
|
{ |
|
52
|
|
|
if (!$this->tagsOrTagExpression) { |
|
53
|
|
|
$tagExpression = ''; |
|
54
|
|
|
} elseif (is_array($this->tagsOrTagExpression)) { |
|
55
|
|
|
$tagExpression = implode(' || ', $this->tagsOrTagExpression); |
|
56
|
|
|
} else { |
|
57
|
|
|
$tagExpression = $this->tagsOrTagExpression; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$headers = [ |
|
61
|
|
|
'Content-Type: '.$this->getContentType(), |
|
62
|
|
|
'ServiceBusNotification-Format: '.$this->getFormat(), |
|
63
|
|
|
]; |
|
64
|
|
|
|
|
65
|
|
|
if ('' !== $tagExpression) { |
|
66
|
|
|
$headers[] = 'ServiceBusNotification-Tags: '.$tagExpression; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($this->scheduleTime instanceof \DateTime) { |
|
70
|
|
|
$this->scheduleTime->setTimeZone(new \DateTimeZone('UTC')); |
|
71
|
|
|
$headers[] = 'ServiceBusNotification-ScheduleTime: '.$this->scheduleTime->format(self::SCHEDULE_TIME_FORMAT); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return $headers; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* {@inheritdoc} |
|
79
|
|
|
*/ |
|
80
|
|
|
public function buildUri($endpoint, $hubPath) |
|
81
|
|
|
{ |
|
82
|
|
|
if ($this->scheduleTime instanceof \DateTime) { |
|
83
|
|
|
return $endpoint.$hubPath.'/schedulednotifications/'; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $endpoint.$hubPath.'/messages/'; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* {@inheritdoc} |
|
91
|
|
|
* |
|
92
|
|
|
* @codeCoverageIgnore |
|
93
|
|
|
*/ |
|
94
|
|
|
public function scrapeResponse($response) |
|
95
|
|
|
{ |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.