Skip to content

Commit 37961a2

Browse files
committed
Fix static errors
1 parent 9c82413 commit 37961a2

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

src/MessageSentReport.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class MessageSentReport {
2020
protected $success;
2121

2222
/**
23-
* @var RequestInterface
23+
* @var RequestInterface | null
2424
*/
2525
protected $request;
2626

2727
/**
28-
* @var ResponseInterface
28+
* @var ResponseInterface | null
2929
*/
3030
protected $response;
3131

@@ -65,9 +65,9 @@ public function setSuccess(bool $success): MessageSentReport {
6565
}
6666

6767
/**
68-
* @return RequestInterface
68+
* @return RequestInterface | null
6969
*/
70-
public function getRequest(): RequestInterface {
70+
public function getRequest(): ?RequestInterface {
7171
return $this->request;
7272
}
7373

@@ -82,9 +82,9 @@ public function setRequest(RequestInterface $request): MessageSentReport {
8282
}
8383

8484
/**
85-
* @return ResponseInterface
85+
* @return ResponseInterface | null
8686
*/
87-
public function getResponse(): ResponseInterface {
87+
public function getResponse(): ?ResponseInterface {
8888
return $this->response;
8989
}
9090

@@ -99,9 +99,13 @@ public function setResponse(ResponseInterface $response): MessageSentReport {
9999
}
100100

101101
/**
102-
* @return string
102+
* @return string | null
103103
*/
104-
public function getEndpoint(): string {
104+
public function getEndpoint(): ?string {
105+
if (!$this->request) {
106+
return null;
107+
}
108+
105109
return $this->request->getUri()->__toString();
106110
}
107111

src/WebPush.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public function __construct(array $auth = [], array $defaultOptions = [], ?int $
100100
* @param array $options Array with several options tied to this notification. If not set, will use the default options that you can set in the WebPush object
101101
* @param array $auth Use this auth details instead of what you provided when creating WebPush
102102
*
103-
* @return array|bool Return an array of information if $flush is set to true and the queued requests has failed.
103+
* @return iterable|bool Return an array of information if $flush is set to true and the queued requests has failed.
104104
* Else return true
105105
*
106106
* @throws \ErrorException
@@ -112,7 +112,12 @@ public function sendNotification(Subscription $subscription, ?string $payload =
112112
throw new \ErrorException('Size of payload must not be greater than '.Encryption::MAX_PAYLOAD_LENGTH.' octets.');
113113
}
114114

115-
$payload = Encryption::padPayload($payload, $this->automaticPadding, $subscription->getContentEncoding());
115+
$contentEncoding = $subscription->getContentEncoding();
116+
if (!$contentEncoding) {
117+
throw new \ErrorException('Subscription should have a content encoding');
118+
}
119+
120+
$payload = Encryption::padPayload($payload, $this->automaticPadding, $contentEncoding);
116121
}
117122

118123
if (array_key_exists('VAPID', $auth)) {
@@ -192,6 +197,10 @@ private function prepare(array $notifications): array
192197
$auth = $notification->getAuth($this->auth);
193198

194199
if (!empty($payload) && !empty($userPublicKey) && !empty($userAuthToken)) {
200+
if (!$contentEncoding) {
201+
throw new \ErrorException('Subscription should have a content encoding');
202+
}
203+
195204
$encrypted = Encryption::encrypt($payload, $userPublicKey, $userAuthToken, $contentEncoding);
196205
$cipherText = $encrypted['cipherText'];
197206
$salt = $encrypted['salt'];
@@ -247,6 +256,10 @@ private function prepare(array $notifications): array
247256
throw new \ErrorException('Audience "'.$audience.'"" could not be generated.');
248257
}
249258

259+
if (!$contentEncoding) {
260+
throw new \ErrorException('Subscription should have a content encoding');
261+
}
262+
250263
$vapidHeaders = VAPID::getVapidHeaders($audience, $vapid['subject'], $vapid['publicKey'], $vapid['privateKey'], $contentEncoding);
251264

252265
$headers['Authorization'] = $vapidHeaders['Authorization'];

0 commit comments

Comments
 (0)