Skip to content

Commit 6264635

Browse files
committed
Apply php-cs-fixer
1 parent 4a8d679 commit 6264635

File tree

5 files changed

+200
-183
lines changed

5 files changed

+200
-183
lines changed

src/Encryption.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public static function padPayload(string $payload, int $maxLengthToPad, string $
3838

3939
if ($contentEncoding === "aesgcm") {
4040
return pack('n*', $padLen).str_pad($payload, $padLen + $payloadLen, chr(0), STR_PAD_LEFT);
41-
} else if ($contentEncoding === "aes128gcm") {
41+
} elseif ($contentEncoding === "aes128gcm") {
4242
return str_pad($payload.chr(2), $padLen + $payloadLen, chr(0), STR_PAD_RIGHT);
4343
} else {
4444
throw new \ErrorException("This content encoding is not supported");
@@ -223,7 +223,7 @@ private static function createInfo(string $type, ?string $context, string $conte
223223
}
224224

225225
return 'Content-Encoding: '.$type.chr(0).'P-256'.$context;
226-
} else if ($contentEncoding === "aes128gcm") {
226+
} elseif ($contentEncoding === "aes128gcm") {
227227
return 'Content-Encoding: '.$type.chr(0);
228228
}
229229

@@ -300,7 +300,7 @@ private static function getIKM(string $userAuthToken, string $userPublicKey, str
300300
if (!empty($userAuthToken)) {
301301
if ($contentEncoding === "aesgcm") {
302302
$info = 'Content-Encoding: auth'.chr(0);
303-
} else if ($contentEncoding === "aes128gcm") {
303+
} elseif ($contentEncoding === "aes128gcm") {
304304
$info = "WebPush: info".chr(0).$userPublicKey.$localPublicKey;
305305
} else {
306306
throw new \ErrorException("This content encoding is not supported");

src/MessageSentReport.php

Lines changed: 160 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -12,155 +12,170 @@
1212
/**
1313
* Standardized response from sending a message
1414
*/
15-
class MessageSentReport implements \JsonSerializable {
16-
17-
/**
18-
* @var boolean
19-
*/
20-
protected $success;
21-
22-
/**
23-
* @var RequestInterface
24-
*/
25-
protected $request;
26-
27-
/**
28-
* @var ResponseInterface | null
29-
*/
30-
protected $response;
31-
32-
/**
33-
* @var string
34-
*/
35-
protected $reason;
36-
37-
/**
38-
* @param RequestInterface $request
39-
* @param ResponseInterface $response
40-
* @param bool $success
41-
* @param string $reason
42-
*/
43-
public function __construct(RequestInterface $request, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK') {
15+
class MessageSentReport implements \JsonSerializable
16+
{
17+
18+
/**
19+
* @var boolean
20+
*/
21+
protected $success;
22+
23+
/**
24+
* @var RequestInterface
25+
*/
26+
protected $request;
27+
28+
/**
29+
* @var ResponseInterface | null
30+
*/
31+
protected $response;
32+
33+
/**
34+
* @var string
35+
*/
36+
protected $reason;
37+
38+
/**
39+
* @param RequestInterface $request
40+
* @param ResponseInterface $response
41+
* @param bool $success
42+
* @param string $reason
43+
*/
44+
public function __construct(RequestInterface $request, ?ResponseInterface $response = null, bool $success = true, $reason = 'OK')
45+
{
4446
$this->request = $request;
4547
$this->response = $response;
46-
$this->success = $success;
47-
$this->reason = $reason;
48-
}
49-
50-
/**
51-
* @return bool
52-
*/
53-
public function isSuccess(): bool {
54-
return $this->success;
55-
}
56-
57-
/**
58-
* @param bool $success
59-
*
60-
* @return MessageSentReport
61-
*/
62-
public function setSuccess(bool $success): MessageSentReport {
63-
$this->success = $success;
64-
return $this;
65-
}
66-
67-
/**
68-
* @return RequestInterface
69-
*/
70-
public function getRequest(): RequestInterface {
71-
return $this->request;
72-
}
73-
74-
/**
75-
* @param RequestInterface $request
76-
*
77-
* @return MessageSentReport
78-
*/
79-
public function setRequest(RequestInterface $request): MessageSentReport {
80-
$this->request = $request;
81-
return $this;
82-
}
83-
84-
/**
85-
* @return ResponseInterface | null
86-
*/
87-
public function getResponse(): ?ResponseInterface {
88-
return $this->response;
89-
}
90-
91-
/**
92-
* @param ResponseInterface $response
93-
*
94-
* @return MessageSentReport
95-
*/
96-
public function setResponse(ResponseInterface $response): MessageSentReport {
97-
$this->response = $response;
98-
return $this;
99-
}
100-
101-
/**
102-
* @return string
103-
*/
104-
public function getEndpoint(): string {
105-
return $this->request->getUri()->__toString();
106-
}
107-
108-
/**
109-
* @return bool
110-
*/
111-
public function isSubscriptionExpired(): bool {
112-
if (!$this->response) {
113-
return false;
114-
}
115-
116-
return \in_array($this->response->getStatusCode(), [404, 410], true);
117-
}
118-
119-
/**
120-
* @return string
121-
*/
122-
public function getReason(): string {
123-
return $this->reason;
124-
}
125-
126-
/**
127-
* @param string $reason
128-
*
129-
* @return MessageSentReport
130-
*/
131-
public function setReason(string $reason): MessageSentReport {
132-
$this->reason = $reason;
133-
return $this;
134-
}
135-
136-
/**
137-
* @return string
138-
*/
139-
public function getRequestPayload(): string {
140-
return $this->request->getBody()->getContents();
141-
}
142-
143-
/**
144-
* @return string | null
145-
*/
146-
public function getResponseContent(): ?string {
48+
$this->success = $success;
49+
$this->reason = $reason;
50+
}
51+
52+
/**
53+
* @return bool
54+
*/
55+
public function isSuccess(): bool
56+
{
57+
return $this->success;
58+
}
59+
60+
/**
61+
* @param bool $success
62+
*
63+
* @return MessageSentReport
64+
*/
65+
public function setSuccess(bool $success): MessageSentReport
66+
{
67+
$this->success = $success;
68+
return $this;
69+
}
70+
71+
/**
72+
* @return RequestInterface
73+
*/
74+
public function getRequest(): RequestInterface
75+
{
76+
return $this->request;
77+
}
78+
79+
/**
80+
* @param RequestInterface $request
81+
*
82+
* @return MessageSentReport
83+
*/
84+
public function setRequest(RequestInterface $request): MessageSentReport
85+
{
86+
$this->request = $request;
87+
return $this;
88+
}
89+
90+
/**
91+
* @return ResponseInterface | null
92+
*/
93+
public function getResponse(): ?ResponseInterface
94+
{
95+
return $this->response;
96+
}
97+
98+
/**
99+
* @param ResponseInterface $response
100+
*
101+
* @return MessageSentReport
102+
*/
103+
public function setResponse(ResponseInterface $response): MessageSentReport
104+
{
105+
$this->response = $response;
106+
return $this;
107+
}
108+
109+
/**
110+
* @return string
111+
*/
112+
public function getEndpoint(): string
113+
{
114+
return $this->request->getUri()->__toString();
115+
}
116+
117+
/**
118+
* @return bool
119+
*/
120+
public function isSubscriptionExpired(): bool
121+
{
122+
if (!$this->response) {
123+
return false;
124+
}
125+
126+
return \in_array($this->response->getStatusCode(), [404, 410], true);
127+
}
128+
129+
/**
130+
* @return string
131+
*/
132+
public function getReason(): string
133+
{
134+
return $this->reason;
135+
}
136+
137+
/**
138+
* @param string $reason
139+
*
140+
* @return MessageSentReport
141+
*/
142+
public function setReason(string $reason): MessageSentReport
143+
{
144+
$this->reason = $reason;
145+
return $this;
146+
}
147+
148+
/**
149+
* @return string
150+
*/
151+
public function getRequestPayload(): string
152+
{
153+
return $this->request->getBody()->getContents();
154+
}
155+
156+
/**
157+
* @return string | null
158+
*/
159+
public function getResponseContent(): ?string
160+
{
147161
if (!$this->response) {
148162
return null;
149163
}
150164

151-
return $this->response->getBody()->getContents();
152-
}
153-
154-
/**
155-
* @return array|mixed
156-
*/
157-
public function jsonSerialize() {
158-
return [
159-
'success' => $this->isSuccess(),
160-
'expired' => $this->isSubscriptionExpired(),
161-
'reason' => $this->reason,
162-
'endpoint' => $this->getEndpoint(),
163-
'payload' => $this->request->getBody()->getContents(),
164-
];
165-
}
165+
return $this->response->getBody()->getContents();
166+
}
167+
168+
/**
169+
* @return array|mixed
170+
*/
171+
public function jsonSerialize()
172+
{
173+
return [
174+
'success' => $this->isSuccess(),
175+
'expired' => $this->isSubscriptionExpired(),
176+
'reason' => $this->reason,
177+
'endpoint' => $this->getEndpoint(),
178+
'payload' => $this->request->getBody()->getContents(),
179+
];
180+
}
166181
}

src/Subscription.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ public function __construct(
6363
* @return Subscription
6464
* @throws \ErrorException
6565
*/
66-
public static function create(array $associativeArray): Subscription {
66+
public static function create(array $associativeArray): Subscription
67+
{
6768
if (array_key_exists('keys', $associativeArray) && is_array($associativeArray['keys'])) {
6869
return new self(
6970
$associativeArray['endpoint'],

src/VAPID.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public static function getVapidHeaders(string $audience, string $subject, string
149149
'Authorization' => 'WebPush '.$jwt,
150150
'Crypto-Key' => 'p256ecdsa='.$encodedPublicKey,
151151
];
152-
} else if ($contentEncoding === 'aes128gcm') {
152+
} elseif ($contentEncoding === 'aes128gcm') {
153153
return [
154154
'Authorization' => 'vapid t='.$jwt.', k='.$encodedPublicKey,
155155
];

0 commit comments

Comments
 (0)