Skip to content

Commit c3372d7

Browse files
authored
#267: Define the SubscriptionInterface (#268)
* #267: Define the `SubscriptionInterface` * Rename Composer package * Revert the package name * Revert the package name
1 parent 3615e3c commit c3372d7

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

src/Notification.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class Notification
1717
{
18-
/** @var Subscription */
18+
/** @var SubscriptionInterface */
1919
private $subscription;
2020

2121
/** @var null|string */
@@ -30,12 +30,12 @@ class Notification
3030
/**
3131
* Notification constructor.
3232
*
33-
* @param Subscription $subscription
33+
* @param SubscriptionInterface $subscription
3434
* @param null|string $payload
3535
* @param array $options
3636
* @param array $auth
3737
*/
38-
public function __construct(Subscription $subscription, ?string $payload, array $options, array $auth)
38+
public function __construct(SubscriptionInterface $subscription, ?string $payload, array $options, array $auth)
3939
{
4040
$this->subscription = $subscription;
4141
$this->payload = $payload;
@@ -44,9 +44,9 @@ public function __construct(Subscription $subscription, ?string $payload, array
4444
}
4545

4646
/**
47-
* @return Subscription
47+
* @return SubscriptionInterface
4848
*/
49-
public function getSubscription(): Subscription
49+
public function getSubscription(): SubscriptionInterface
5050
{
5151
return $this->subscription;
5252
}

src/Subscription.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace Minishlink\WebPush;
1515

16-
class Subscription
16+
class Subscription implements SubscriptionInterface
1717
{
1818
/** @var string */
1919
private $endpoint;
@@ -60,10 +60,10 @@ public function __construct(
6060
* Subscription factory.
6161
*
6262
* @param array $associativeArray (with keys endpoint, publicKey, authToken, contentEncoding)
63-
* @return Subscription
63+
* @return self
6464
* @throws \ErrorException
6565
*/
66-
public static function create(array $associativeArray): Subscription
66+
public static function create(array $associativeArray): self
6767
{
6868
if (array_key_exists('keys', $associativeArray) && is_array($associativeArray['keys'])) {
6969
return new self(
@@ -89,31 +89,31 @@ public static function create(array $associativeArray): Subscription
8989
}
9090

9191
/**
92-
* @return string
92+
* {@inheritDoc}
9393
*/
9494
public function getEndpoint(): string
9595
{
9696
return $this->endpoint;
9797
}
9898

9999
/**
100-
* @return null|string
100+
* {@inheritDoc}
101101
*/
102102
public function getPublicKey(): ?string
103103
{
104104
return $this->publicKey;
105105
}
106106

107107
/**
108-
* @return null|string
108+
* {@inheritDoc}
109109
*/
110110
public function getAuthToken(): ?string
111111
{
112112
return $this->authToken;
113113
}
114114

115115
/**
116-
* @return null|string
116+
* {@inheritDoc}
117117
*/
118118
public function getContentEncoding(): ?string
119119
{

src/SubscriptionInterface.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the WebPush library.
7+
*
8+
* (c) Louis Lagrange <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace Minishlink\WebPush;
15+
16+
/**
17+
* @author Sergii Bondarenko <[email protected]>
18+
*/
19+
interface SubscriptionInterface {
20+
/**
21+
* @return string
22+
*/
23+
public function getEndpoint(): string;
24+
25+
/**
26+
* @return null|string
27+
*/
28+
public function getPublicKey(): ?string;
29+
30+
/**
31+
* @return null|string
32+
*/
33+
public function getAuthToken(): ?string;
34+
35+
/**
36+
* @return null|string
37+
*/
38+
public function getContentEncoding(): ?string;
39+
}

src/WebPush.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function __construct(array $auth = [], array $defaultOptions = [], ?int $
104104
/**
105105
* Send a notification.
106106
*
107-
* @param Subscription $subscription
107+
* @param SubscriptionInterface $subscription
108108
* @param string|null $payload If you want to send an array, json_encode it
109109
* @param bool $flush If you want to flush directly (usually when you send only one notification)
110110
* @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
@@ -115,7 +115,7 @@ public function __construct(array $auth = [], array $defaultOptions = [], ?int $
115115
*
116116
* @throws \ErrorException
117117
*/
118-
public function sendNotification(Subscription $subscription, ?string $payload = null, bool $flush = false, array $options = [], array $auth = [])
118+
public function sendNotification(SubscriptionInterface $subscription, ?string $payload = null, bool $flush = false, array $options = [], array $auth = [])
119119
{
120120
if (isset($payload)) {
121121
if (Utils::safeStrlen($payload) > Encryption::MAX_PAYLOAD_LENGTH) {

tests/WebPushTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Minishlink\WebPush\WebPush;
1515
use Minishlink\WebPush\Subscription;
16+
use Minishlink\WebPush\SubscriptionInterface;
1617

1718
final class WebPushTest extends PHPUnit\Framework\TestCase
1819
{
@@ -88,7 +89,7 @@ public function notificationProvider(): array
8889
/**
8990
* @dataProvider notificationProvider
9091
*
91-
* @param Subscription $subscription
92+
* @param SubscriptionInterface $subscription
9293
* @param string $payload
9394
* @throws ErrorException
9495
*/

0 commit comments

Comments
 (0)