1616class Subscription implements SubscriptionInterface
1717{
1818 /**
19- * @param string|null $contentEncoding (Optional) Must be "aesgcm"
19+ * @param string $contentEncoding (Optional) defaults to "aesgcm"
2020 * @throws \ErrorException
2121 */
2222 public function __construct (
23- private string $ endpoint ,
24- private ? string $ publicKey = null ,
25- private ? string $ authToken = null ,
26- private ? string $ contentEncoding = null
23+ private readonly string $ endpoint ,
24+ private readonly string $ publicKey ,
25+ private readonly string $ authToken ,
26+ private readonly string $ contentEncoding = " aesgcm " ,
2727 ) {
28- if ( $ publicKey || $ authToken || $ contentEncoding ) {
29- $ supportedContentEncodings = [ ' aesgcm ' , ' aes128gcm ' ];
30- if ( $ contentEncoding && ! in_array ( $ contentEncoding, $ supportedContentEncodings , true )) {
31- throw new \ ErrorException ( ' This content encoding ( ' . $ contentEncoding . ' ) is not supported. ' );
32- }
33- $ this -> contentEncoding = $ contentEncoding ?: " aesgcm " ;
28+ $ supportedContentEncodings = [ ' aesgcm ' , ' aes128gcm ' ];
29+ if ( $ contentEncoding && ! in_array ( $ contentEncoding , $ supportedContentEncodings, true )) {
30+ throw new \ ErrorException ( ' This content encoding ( ' . $ contentEncoding. ' ) is not supported. ' );
31+ }
32+ if ( empty ( $ publicKey ) || empty ( $ authToken ) || empty ( $ contentEncoding )) {
33+ throw new \ ValueError ( ' Missing values. ' ) ;
3434 }
3535 }
3636
@@ -42,55 +42,41 @@ public static function create(array $associativeArray): self
4242 {
4343 if (array_key_exists ('keys ' , $ associativeArray ) && is_array ($ associativeArray ['keys ' ])) {
4444 return new self (
45- $ associativeArray ['endpoint ' ],
46- $ associativeArray ['keys ' ]['p256dh ' ] ?? null ,
47- $ associativeArray ['keys ' ]['auth ' ] ?? null ,
45+ $ associativeArray ['endpoint ' ] ?? "" ,
46+ $ associativeArray ['keys ' ]['p256dh ' ] ?? "" ,
47+ $ associativeArray ['keys ' ]['auth ' ] ?? "" ,
4848 $ associativeArray ['contentEncoding ' ] ?? "aesgcm "
4949 );
5050 }
5151
5252 if (array_key_exists ('publicKey ' , $ associativeArray ) || array_key_exists ('authToken ' , $ associativeArray ) || array_key_exists ('contentEncoding ' , $ associativeArray )) {
5353 return new self (
54- $ associativeArray ['endpoint ' ],
55- $ associativeArray ['publicKey ' ] ?? null ,
56- $ associativeArray ['authToken ' ] ?? null ,
54+ $ associativeArray ['endpoint ' ] ?? "" ,
55+ $ associativeArray ['publicKey ' ] ?? "" ,
56+ $ associativeArray ['authToken ' ] ?? "" ,
5757 $ associativeArray ['contentEncoding ' ] ?? "aesgcm "
5858 );
5959 }
6060
61- return new self (
62- $ associativeArray ['endpoint ' ]
63- );
61+ throw new \ValueError ('Missing values. ' );
6462 }
6563
66- /**
67- * {@inheritDoc}
68- */
6964 public function getEndpoint (): string
7065 {
7166 return $ this ->endpoint ;
7267 }
7368
74- /**
75- * {@inheritDoc}
76- */
77- public function getPublicKey (): ?string
69+ public function getPublicKey (): string
7870 {
7971 return $ this ->publicKey ;
8072 }
8173
82- /**
83- * {@inheritDoc}
84- */
85- public function getAuthToken (): ?string
74+ public function getAuthToken (): string
8675 {
8776 return $ this ->authToken ;
8877 }
8978
90- /**
91- * {@inheritDoc}
92- */
93- public function getContentEncoding (): ?string
79+ public function getContentEncoding (): string
9480 {
9581 return $ this ->contentEncoding ;
9682 }
0 commit comments