kreait / firebase-php

@@ -7,15 +7,13 @@
Loading
7 7
use GuzzleHttp\ClientInterface;
8 8
use InvalidArgumentException;
9 9
use Kreait\Firebase\DynamicLink\CreateDynamicLink;
10 -
use Kreait\Firebase\DynamicLink\CreateDynamicLink\FailedToCreateDynamicLink;
11 10
use Kreait\Firebase\DynamicLink\DynamicLinkStatistics;
12 11
use Kreait\Firebase\DynamicLink\GetStatisticsForDynamicLink;
13 12
use Kreait\Firebase\DynamicLink\ShortenLongDynamicLink;
14 -
use Kreait\Firebase\DynamicLink\ShortenLongDynamicLink\FailedToShortenLongDynamicLink;
15 13
use Kreait\Firebase\Value\Url;
16 14
use Psr\Http\Message\UriInterface;
17 15
18 -
final class DynamicLinks
16 +
final class DynamicLinks implements Contract\DynamicLinks
19 17
{
20 18
    /** @var ClientInterface */
21 19
    private $apiClient;
@@ -46,34 +44,16 @@
Loading
46 44
        return $service;
47 45
    }
48 46
49 -
    /**
50 -
     * @param string|Url|UriInterface|CreateDynamicLink|array|mixed $url
51 -
     *
52 -
     * @throws InvalidArgumentException
53 -
     * @throws FailedToCreateDynamicLink
54 -
     */
55 47
    public function createUnguessableLink($url): DynamicLink
56 48
    {
57 49
        return $this->createDynamicLink($url, CreateDynamicLink::WITH_UNGUESSABLE_SUFFIX);
58 50
    }
59 51
60 -
    /**
61 -
     * @param string|Url|UriInterface|CreateDynamicLink|array|mixed $url
62 -
     *
63 -
     * @throws InvalidArgumentException
64 -
     * @throws FailedToCreateDynamicLink
65 -
     */
66 52
    public function createShortLink($url): DynamicLink
67 53
    {
68 54
        return $this->createDynamicLink($url, CreateDynamicLink::WITH_SHORT_SUFFIX);
69 55
    }
70 56
71 -
    /**
72 -
     * @param string|Url|UriInterface|CreateDynamicLink|array|mixed $actionOrParametersOrUrl
73 -
     *
74 -
     * @throws InvalidArgumentException
75 -
     * @throws FailedToCreateDynamicLink
76 -
     */
77 57
    public function createDynamicLink($actionOrParametersOrUrl, ?string $suffixType = null): DynamicLink
78 58
    {
79 59
        $action = $this->ensureCreateAction($actionOrParametersOrUrl);
@@ -92,12 +72,6 @@
Loading
92 72
        return (new CreateDynamicLink\GuzzleApiClientHandler($this->apiClient))->handle($action);
93 73
    }
94 74
95 -
    /**
96 -
     * @param string|Url|UriInterface|ShortenLongDynamicLink|array|mixed $longDynamicLinkOrAction
97 -
     *
98 -
     * @throws InvalidArgumentException
99 -
     * @throws FailedToShortenLongDynamicLink
100 -
     */
101 75
    public function shortenLongDynamicLink($longDynamicLinkOrAction, ?string $suffixType = null): DynamicLink
102 76
    {
103 77
        $action = $this->ensureShortenAction($longDynamicLinkOrAction);
@@ -111,12 +85,6 @@
Loading
111 85
        return (new ShortenLongDynamicLink\GuzzleApiClientHandler($this->apiClient))->handle($action);
112 86
    }
113 87
114 -
    /**
115 -
     * @param string|Url|UriInterface|GetStatisticsForDynamicLink|mixed $dynamicLinkOrAction
116 -
     *
117 -
     * @throws InvalidArgumentException
118 -
     * @throws GetStatisticsForDynamicLink\FailedToGetStatisticsForDynamicLink
119 -
     */
120 88
    public function getStatistics($dynamicLinkOrAction, ?int $durationInDays = null): DynamicLinkStatistics
121 89
    {
122 90
        $action = $this->ensureGetStatisticsAction($dynamicLinkOrAction);

@@ -8,7 +8,7 @@
Loading
8 8
use Google\Cloud\Storage\StorageClient;
9 9
use Kreait\Firebase\Exception\RuntimeException;
10 10
11 -
class Storage
11 +
class Storage implements Contract\Storage
12 12
{
13 13
    /** @var StorageClient */
14 14
    private $storageClient;

@@ -6,16 +6,11 @@
Loading
6 6
7 7
use Firebase\Auth\Token\Domain\Generator as TokenGenerator;
8 8
use Firebase\Auth\Token\Domain\Verifier;
9 -
use Firebase\Auth\Token\Exception\ExpiredToken;
10 -
use Firebase\Auth\Token\Exception\InvalidSignature;
11 9
use Firebase\Auth\Token\Exception\InvalidToken;
12 -
use Firebase\Auth\Token\Exception\IssuedInTheFuture;
13 -
use Firebase\Auth\Token\Exception\UnknownKey;
14 10
use Kreait\Firebase\Auth\ActionCodeSettings;
15 11
use Kreait\Firebase\Auth\ActionCodeSettings\ValidatedActionCodeSettings;
16 12
use Kreait\Firebase\Auth\ApiClient;
17 13
use Kreait\Firebase\Auth\CreateActionLink;
18 -
use Kreait\Firebase\Auth\CreateActionLink\FailedToCreateActionLink;
19 14
use Kreait\Firebase\Auth\IdTokenVerifier;
20 15
use Kreait\Firebase\Auth\SendActionLink;
21 16
use Kreait\Firebase\Auth\SendActionLink\FailedToSendActionLink;
@@ -30,11 +25,7 @@
Loading
30 25
use Kreait\Firebase\Auth\SignInWithRefreshToken;
31 26
use Kreait\Firebase\Auth\TenantId;
32 27
use Kreait\Firebase\Auth\UserRecord;
33 -
use Kreait\Firebase\Exception\Auth\ExpiredOobCode;
34 -
use Kreait\Firebase\Exception\Auth\InvalidOobCode;
35 -
use Kreait\Firebase\Exception\Auth\OperationNotAllowed;
36 28
use Kreait\Firebase\Exception\Auth\RevokedIdToken;
37 -
use Kreait\Firebase\Exception\Auth\UserDisabled;
38 29
use Kreait\Firebase\Exception\Auth\UserNotFound;
39 30
use Kreait\Firebase\Exception\InvalidArgumentException;
40 31
use Kreait\Firebase\Util\Deprecation;
@@ -52,7 +43,7 @@
Loading
52 43
use Throwable;
53 44
use Traversable;
54 45
55 -
class Auth
46 +
class Auth implements Contract\Auth
56 47
{
57 48
    /** @var ApiClient */
58 49
    private $client;
@@ -91,13 +82,6 @@
Loading
91 82
        }
92 83
    }
93 84
94 -
    /**
95 -
     * @param Uid|string $uid
96 -
     *
97 -
     * @throws UserNotFound
98 -
     * @throws Exception\AuthException
99 -
     * @throws Exception\FirebaseException
100 -
     */
101 85
    public function getUser($uid): UserRecord
102 86
    {
103 87
        $userRecords = $this->getUsers([$uid]);
@@ -109,14 +93,6 @@
Loading
109 93
        throw new UserNotFound("No user with uid '{$uid}' found.");
110 94
    }
111 95
112 -
    /**
113 -
     * @param array<Uid|string> $uids
114 -
     *
115 -
     * @throws Exception\AuthException
116 -
     * @throws Exception\FirebaseException
117 -
     *
118 -
     * @return array<string, UserRecord|null>
119 -
     */
120 96
    public function getUsers(array $uids): array
121 97
    {
122 98
        $uids = \array_map(static function ($uid) {
@@ -139,12 +115,6 @@
Loading
139 115
        return $users;
140 116
    }
141 117
142 -
    /**
143 -
     * @throws Exception\AuthException
144 -
     * @throws Exception\FirebaseException
145 -
     *
146 -
     * @return Traversable<UserRecord>|UserRecord[]
147 -
     */
148 118
    public function listUsers(int $maxResults = 1000, int $batchSize = 1000): Traversable
149 119
    {
150 120
        $pageToken = null;
@@ -166,14 +136,6 @@
Loading
166 136
        } while ($pageToken);
167 137
    }
168 138
169 -
    /**
170 -
     * Creates a new user with the provided properties.
171 -
     *
172 -
     * @param array<string, mixed>|Request\CreateUser $properties
173 -
     *
174 -
     * @throws Exception\AuthException
175 -
     * @throws Exception\FirebaseException
176 -
     */
177 139
    public function createUser($properties): UserRecord
178 140
    {
179 141
        $request = $properties instanceof Request\CreateUser
@@ -185,15 +147,6 @@
Loading
185 147
        return $this->getUserRecordFromResponse($response);
186 148
    }
187 149
188 -
    /**
189 -
     * Updates the given user with the given properties.
190 -
     *
191 -
     * @param Uid|string $uid
192 -
     * @param array<string, mixed>|Request\UpdateUser $properties
193 -
     *
194 -
     * @throws Exception\AuthException
195 -
     * @throws Exception\FirebaseException
196 -
     */
197 150
    public function updateUser($uid, $properties): UserRecord
198 151
    {
199 152
        $request = $properties instanceof Request\UpdateUser
@@ -207,13 +160,6 @@
Loading
207 160
        return $this->getUserRecordFromResponse($response);
208 161
    }
209 162
210 -
    /**
211 -
     * @param Email|string $email
212 -
     * @param ClearTextPassword|string $password
213 -
     *
214 -
     * @throws Exception\AuthException
215 -
     * @throws Exception\FirebaseException
216 -
     */
217 163
    public function createUserWithEmailAndPassword($email, $password): UserRecord
218 164
    {
219 165
        return $this->createUser(Request\CreateUser::new()
@@ -222,13 +168,6 @@
Loading
222 168
        );
223 169
    }
224 170
225 -
    /**
226 -
     * @param Email|string $email
227 -
     *
228 -
     * @throws UserNotFound
229 -
     * @throws Exception\AuthException
230 -
     * @throws Exception\FirebaseException
231 -
     */
232 171
    public function getUserByEmail($email): UserRecord
233 172
    {
234 173
        $email = $email instanceof Email ? $email : new Email($email);
@@ -244,12 +183,6 @@
Loading
244 183
        return UserRecord::fromResponseData($data['users'][0]);
245 184
    }
246 185
247 -
    /**
248 -
     * @param PhoneNumber|string $phoneNumber
249 -
     *
250 -
     * @throws Exception\AuthException
251 -
     * @throws Exception\FirebaseException
252 -
     */
253 186
    public function getUserByPhoneNumber($phoneNumber): UserRecord
254 187
    {
255 188
        $phoneNumber = $phoneNumber instanceof PhoneNumber ? $phoneNumber : new PhoneNumber($phoneNumber);
@@ -265,68 +198,31 @@
Loading
265 198
        return UserRecord::fromResponseData($data['users'][0]);
266 199
    }
267 200
268 -
    /**
269 -
     * @throws Exception\AuthException
270 -
     * @throws Exception\FirebaseException
271 -
     */
272 201
    public function createAnonymousUser(): UserRecord
273 202
    {
274 203
        return $this->createUser(Request\CreateUser::new());
275 204
    }
276 205
277 -
    /**
278 -
     * @param Uid|string $uid
279 -
     * @param ClearTextPassword|string $newPassword
280 -
     *
281 -
     * @throws Exception\AuthException
282 -
     * @throws Exception\FirebaseException
283 -
     */
284 206
    public function changeUserPassword($uid, $newPassword): UserRecord
285 207
    {
286 208
        return $this->updateUser($uid, Request\UpdateUser::new()->withClearTextPassword($newPassword));
287 209
    }
288 210
289 -
    /**
290 -
     * @param Uid|string $uid
291 -
     * @param Email|string $newEmail
292 -
     *
293 -
     * @throws Exception\AuthException
294 -
     * @throws Exception\FirebaseException
295 -
     */
296 211
    public function changeUserEmail($uid, $newEmail): UserRecord
297 212
    {
298 213
        return $this->updateUser($uid, Request\UpdateUser::new()->withEmail($newEmail));
299 214
    }
300 215
301 -
    /**
302 -
     * @param Uid|string $uid
303 -
     *
304 -
     * @throws Exception\AuthException
305 -
     * @throws Exception\FirebaseException
306 -
     */
307 216
    public function enableUser($uid): UserRecord
308 217
    {
309 218
        return $this->updateUser($uid, Request\UpdateUser::new()->markAsEnabled());
310 219
    }
311 220
312 -
    /**
313 -
     * @param Uid|string $uid
314 -
     *
315 -
     * @throws Exception\AuthException
316 -
     * @throws Exception\FirebaseException
317 -
     */
318 221
    public function disableUser($uid): UserRecord
319 222
    {
320 223
        return $this->updateUser($uid, Request\UpdateUser::new()->markAsDisabled());
321 224
    }
322 225
323 -
    /**
324 -
     * @param Uid|string $uid
325 -
     *
326 -
     * @throws UserNotFound
327 -
     * @throws Exception\AuthException
328 -
     * @throws Exception\FirebaseException
329 -
     */
330 226
    public function deleteUser($uid): void
331 227
    {
332 228
        $uid = $uid instanceof Uid ? $uid : new Uid($uid);
@@ -338,12 +234,6 @@
Loading
338 234
        }
339 235
    }
340 236
341 -
    /**
342 -
     * @param Email|string $email
343 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
344 -
     *
345 -
     * @throws FailedToCreateActionLink
346 -
     */
347 237
    public function getEmailActionLink(string $type, $email, $actionCodeSettings = null): string
348 238
    {
349 239
        $email = $email instanceof Email ? $email : new Email($email);
@@ -360,13 +250,6 @@
Loading
360 250
            ->handle(CreateActionLink::new($type, $email, $actionCodeSettings));
361 251
    }
362 252
363 -
    /**
364 -
     * @param Email|string $email
365 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
366 -
     *
367 -
     * @throws UserNotFound
368 -
     * @throws FailedToSendActionLink
369 -
     */
370 253
    public function sendEmailActionLink(string $type, $email, $actionCodeSettings = null, ?string $locale = null): void
371 254
    {
372 255
        $email = $email instanceof Email ? $email : new Email($email);
@@ -411,82 +294,40 @@
Loading
411 294
        (new SendActionLink\GuzzleApiClientHandler($this->client))->handle($sendAction);
412 295
    }
413 296
414 -
    /**
415 -
     * @param Email|string $email
416 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
417 -
     *
418 -
     * @throws FailedToCreateActionLink
419 -
     */
420 297
    public function getEmailVerificationLink($email, $actionCodeSettings = null): string
421 298
    {
422 299
        return $this->getEmailActionLink('VERIFY_EMAIL', $email, $actionCodeSettings);
423 300
    }
424 301
425 -
    /**
426 -
     * @param Email|string $email
427 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
428 -
     *
429 -
     * @throws FailedToSendActionLink
430 -
     */
431 302
    public function sendEmailVerificationLink($email, $actionCodeSettings = null, ?string $locale = null): void
432 303
    {
433 304
        $this->sendEmailActionLink('VERIFY_EMAIL', $email, $actionCodeSettings, $locale);
434 305
    }
435 306
436 -
    /**
437 -
     * @param Email|string $email
438 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
439 -
     *
440 -
     * @throws FailedToCreateActionLink
441 -
     */
442 307
    public function getPasswordResetLink($email, $actionCodeSettings = null): string
443 308
    {
444 309
        return $this->getEmailActionLink('PASSWORD_RESET', $email, $actionCodeSettings);
445 310
    }
446 311
447 -
    /**
448 -
     * @param Email|string $email
449 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
450 -
     *
451 -
     * @throws FailedToSendActionLink
452 -
     */
453 312
    public function sendPasswordResetLink($email, $actionCodeSettings = null, ?string $locale = null): void
454 313
    {
455 314
        $this->sendEmailActionLink('PASSWORD_RESET', $email, $actionCodeSettings, $locale);
456 315
    }
457 316
458 -
    /**
459 -
     * @param Email|string $email
460 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
461 -
     *
462 -
     * @throws FailedToCreateActionLink
463 -
     */
464 317
    public function getSignInWithEmailLink($email, $actionCodeSettings = null): string
465 318
    {
466 319
        return $this->getEmailActionLink('EMAIL_SIGNIN', $email, $actionCodeSettings);
467 320
    }
468 321
469 -
    /**
470 -
     * @param Email|string $email
471 -
     * @param ActionCodeSettings|array<string, mixed>|null $actionCodeSettings
472 -
     *
473 -
     * @throws FailedToSendActionLink
474 -
     */
475 322
    public function sendSignInWithEmailLink($email, $actionCodeSettings = null, ?string $locale = null): void
476 323
    {
477 324
        $this->sendEmailActionLink('EMAIL_SIGNIN', $email, $actionCodeSettings, $locale);
478 325
    }
479 326
480 327
    /**
481 -
     * @deprecated 5.4.0 use {@see setCustomUserClaims}($id, array $claims) instead
482 -
     * @see setCustomUserClaims
483 -
     * @codeCoverageIgnore
484 -
     *
485 -
     * @param Uid|string $uid
486 -
     * @param array<string, mixed> $attributes
328 +
     * {@inheritdoc}
487 329
     *
488 -
     * @throws Exception\AuthException
489 -
     * @throws Exception\FirebaseException
330 +
     * @deprecated 5.4.0 use {@see setCustomUserClaims}($id, array $claims) instead
490 331
     */
491 332
    public function setCustomUserAttributes($uid, array $attributes): UserRecord
492 333
    {
@@ -498,13 +339,9 @@
Loading
498 339
    }
499 340
500 341
    /**
501 -
     * @deprecated 5.4.0 use {@see setCustomUserClaims}($uid) instead
502 -
     * @see removeCustomUserClaims
342 +
     * {@inheritdoc}
503 343
     *
504 -
     * @param Uid|string $uid
505 -
     *
506 -
     * @throws Exception\AuthException
507 -
     * @throws Exception\FirebaseException
344 +
     * @deprecated 5.4.0 use {@see setCustomUserClaims}($uid) instead
508 345
     */
509 346
    public function deleteCustomUserAttributes($uid): UserRecord
510 347
    {
@@ -515,17 +352,6 @@
Loading
515 352
        return $this->getUser($uid);
516 353
    }
517 354
518 -
    /**
519 -
     * Sets additional developer claims on an existing user identified by the provided UID.
520 -
     *
521 -
     * @see https://firebase.google.com/docs/auth/admin/custom-claims
522 -
     *
523 -
     * @param Uid|string $uid
524 -
     * @param array<string, mixed>|null $claims
525 -
     *
526 -
     * @throws Exception\AuthException
527 -
     * @throws Exception\FirebaseException
528 -
     */
529 355
    public function setCustomUserClaims($uid, ?array $claims): void
530 356
    {
531 357
        $uid = $uid instanceof Uid ? (string) $uid : $uid;
@@ -534,10 +360,6 @@
Loading
534 360
        $this->client->setCustomUserClaims($uid, $claims);
535 361
    }
536 362
537 -
    /**
538 -
     * @param Uid|string $uid
539 -
     * @param array<string, mixed> $claims
540 -
     */
541 363
    public function createCustomToken($uid, array $claims = []): Token
542 364
    {
543 365
        $uid = $uid instanceof Uid ? $uid : new Uid($uid);
@@ -554,27 +376,6 @@
Loading
554 376
        }
555 377
    }
556 378
557 -
    /**
558 -
     * Verifies a JWT auth token. Returns a Promise with the tokens claims. Rejects the promise if the token
559 -
     * could not be verified. If checkRevoked is set to true, verifies if the session corresponding to the
560 -
     * ID token was revoked. If the corresponding user's session was invalidated, a RevokedToken
561 -
     * exception is thrown. If not specified the check is not applied.
562 -
     *
563 -
     * NOTE: Allowing time inconsistencies might impose a security risk. Do this only when you are not able
564 -
     * to fix your environment's time to be consistent with Google's servers. This parameter is here
565 -
     * for backwards compatibility reasons, and will be removed in the next major version. You
566 -
     * shouldn't rely on it.
567 -
     *
568 -
     * @param Token|string $idToken the JWT to verify
569 -
     * @param bool $checkIfRevoked whether to check if the ID token is revoked
570 -
     *
571 -
     * @throws \InvalidArgumentException if the token could not be parsed
572 -
     * @throws InvalidToken if the token could be parsed, but is invalid for any reason (invalid signature, expired, time errors)
573 -
     * @throws InvalidSignature if the signature doesn't match
574 -
     * @throws ExpiredToken if the token is expired
575 -
     * @throws IssuedInTheFuture if the token is issued in the future
576 -
     * @throws UnknownKey if the token's kid header doesnt' contain a known key
577 -
     */
578 379
    public function verifyIdToken($idToken, bool $checkIfRevoked = false): Token
579 380
    {
580 381
        $leewayInSeconds = 300;
@@ -617,34 +418,12 @@
Loading
617 418
        return $verifiedToken;
618 419
    }
619 420
620 -
    /**
621 -
     * Verifies the given password reset code.
622 -
     *
623 -
     * @see https://firebase.google.com/docs/reference/rest/auth#section-verify-password-reset-code
624 -
     *
625 -
     * @throws ExpiredOobCode
626 -
     * @throws InvalidOobCode
627 -
     * @throws OperationNotAllowed
628 -
     * @throws Exception\AuthException
629 -
     * @throws Exception\FirebaseException
630 -
     */
631 421
    public function verifyPasswordResetCode(string $oobCode): void
632 422
    {
633 423
        // Not returning the email on purpose to not break BC
634 424
        $this->verifyPasswordResetCodeAndReturnEmail($oobCode);
635 425
    }
636 426
637 -
    /**
638 -
     * Verifies the given password reset code and returns the associated user's email address.
639 -
     *
640 -
     * @see https://firebase.google.com/docs/reference/rest/auth#section-verify-password-reset-code
641 -
     *
642 -
     * @throws ExpiredOobCode
643 -
     * @throws InvalidOobCode
644 -
     * @throws OperationNotAllowed
645 -
     * @throws Exception\AuthException
646 -
     * @throws Exception\FirebaseException
647 -
     */
648 427
    public function verifyPasswordResetCodeAndReturnEmail(string $oobCode): Email
649 428
    {
650 429
        $response = $this->client->verifyPasswordResetCode($oobCode);
@@ -654,44 +433,12 @@
Loading
654 433
        return new Email($email);
655 434
    }
656 435
657 -
    /**
658 -
     * Applies the password reset requested via the given OOB code.
659 -
     *
660 -
     * @see https://firebase.google.com/docs/reference/rest/auth#section-confirm-reset-password
661 -
     *
662 -
     * @param string $oobCode the email action code sent to the user's email for resetting the password
663 -
     * @param ClearTextPassword|string $newPassword
664 -
     * @param bool $invalidatePreviousSessions Invalidate sessions initialized with the previous credentials
665 -
     *
666 -
     * @throws ExpiredOobCode
667 -
     * @throws InvalidOobCode
668 -
     * @throws OperationNotAllowed
669 -
     * @throws UserDisabled
670 -
     * @throws Exception\AuthException
671 -
     * @throws Exception\FirebaseException
672 -
     */
673 436
    public function confirmPasswordReset(string $oobCode, $newPassword, bool $invalidatePreviousSessions = true): void
674 437
    {
675 438
        // Not returning the email on purpose to not break BC
676 439
        $this->confirmPasswordResetAndReturnEmail($oobCode, $newPassword, $invalidatePreviousSessions);
677 440
    }
678 441
679 -
    /**
680 -
     * Applies the password reset requested via the given OOB code and returns the associated user's email address.
681 -
     *
682 -
     * @see https://firebase.google.com/docs/reference/rest/auth#section-confirm-reset-password
683 -
     *
684 -
     * @param string $oobCode the email action code sent to the user's email for resetting the password
685 -
     * @param ClearTextPassword|string $newPassword
686 -
     * @param bool $invalidatePreviousSessions Invalidate sessions initialized with the previous credentials
687 -
     *
688 -
     * @throws ExpiredOobCode
689 -
     * @throws InvalidOobCode
690 -
     * @throws OperationNotAllowed
691 -
     * @throws UserDisabled
692 -
     * @throws Exception\AuthException
693 -
     * @throws Exception\FirebaseException
694 -
     */
695 442
    public function confirmPasswordResetAndReturnEmail(string $oobCode, $newPassword, bool $invalidatePreviousSessions = true): Email
696 443
    {
697 444
        $newPassword = $newPassword instanceof ClearTextPassword ? $newPassword : new ClearTextPassword($newPassword);
@@ -707,17 +454,6 @@
Loading
707 454
        return new Email($email);
708 455
    }
709 456
710 -
    /**
711 -
     * Revokes all refresh tokens for the specified user identified by the uid provided.
712 -
     * In addition to revoking all refresh tokens for a user, all ID tokens issued
713 -
     * before revocation will also be revoked on the Auth backend. Any request with an
714 -
     * ID token generated before revocation will be rejected with a token expired error.
715 -
     *
716 -
     * @param Uid|string $uid the user whose tokens are to be revoked
717 -
     *
718 -
     * @throws Exception\AuthException
719 -
     * @throws Exception\FirebaseException
720 -
     */
721 457
    public function revokeRefreshTokens($uid): void
722 458
    {
723 459
        $uid = $uid instanceof Uid ? $uid : new Uid($uid);
@@ -725,13 +461,6 @@
Loading
725 461
        $this->client->revokeRefreshTokens((string) $uid);
726 462
    }
727 463
728 -
    /**
729 -
     * @param Uid|string $uid
730 -
     * @param Provider[]|string[]|string $provider
731 -
     *
732 -
     * @throws Exception\AuthException
733 -
     * @throws Exception\FirebaseException
734 -
     */
735 464
    public function unlinkProvider($uid, $provider): UserRecord
736 465
    {
737 466
        $uid = $uid instanceof Uid ? $uid : new Uid($uid);
@@ -744,12 +473,6 @@
Loading
744 473
        return $this->getUserRecordFromResponse($response);
745 474
    }
746 475
747 -
    /**
748 -
     * @param UserRecord|Uid|string $user
749 -
     * @param array<string, mixed>|null $claims
750 -
     *
751 -
     * @throws FailedToSignIn
752 -
     */
753 476
    public function signInAsUser($user, ?array $claims = null): SignInResult
754 477
    {
755 478
        $claims = $claims ?? [];
@@ -766,11 +489,6 @@
Loading
766 489
        return $this->signInHandler->handle($action);
767 490
    }
768 491
769 -
    /**
770 -
     * @param Token|string $token
771 -
     *
772 -
     * @throws FailedToSignIn
773 -
     */
774 492
    public function signInWithCustomToken($token): SignInResult
775 493
    {
776 494
        $token = $token instanceof Token ? $token->toString() : $token;
@@ -784,9 +502,6 @@
Loading
784 502
        return $this->signInHandler->handle($action);
785 503
    }
786 504
787 -
    /**
788 -
     * @throws FailedToSignIn
789 -
     */
790 505
    public function signInWithRefreshToken(string $refreshToken): SignInResult
791 506
    {
792 507
        $action = SignInWithRefreshToken::fromValue($refreshToken);
@@ -798,12 +513,6 @@
Loading
798 513
        return $this->signInHandler->handle($action);
799 514
    }
800 515
801 -
    /**
802 -
     * @param string|Email $email
803 -
     * @param string|ClearTextPassword $clearTextPassword
804 -
     *
805 -
     * @throws FailedToSignIn
806 -
     */
807 516
    public function signInWithEmailAndPassword($email, $clearTextPassword): SignInResult
808 517
    {
809 518
        $email = $email instanceof Email ? (string) $email : $email;
@@ -818,12 +527,6 @@
Loading
818 527
        return $this->signInHandler->handle($action);
819 528
    }
820 529
821 -
    /**
822 -
     * @param string|Email $email
823 -
     * @param string $oobCode
824 -
     *
825 -
     * @throws FailedToSignIn
826 -
     */
827 530
    public function signInWithEmailAndOobCode($email, $oobCode): SignInResult
828 531
    {
829 532
        $email = $email instanceof Email ? (string) $email : $email;
@@ -837,9 +540,6 @@
Loading
837 540
        return $this->signInHandler->handle($action);
838 541
    }
839 542
840 -
    /**
841 -
     * @throws FailedToSignIn
842 -
     */
843 543
    public function signInAnonymously(): SignInResult
844 544
    {
845 545
        $action = SignInAnonymously::new();
@@ -876,14 +576,6 @@
Loading
876 576
        return $this->signInWithIdpAccessToken(Provider::FACEBOOK, $accessToken, $redirectUrl);
877 577
    }
878 578
879 -
    /**
880 -
     * @see https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/signInWithIdp
881 -
     *
882 -
     * @param Provider|string $provider
883 -
     * @param UriInterface|string|null $redirectUrl
884 -
     *
885 -
     * @throws FailedToSignIn
886 -
     */
887 579
    public function signInWithIdpAccessToken($provider, string $accessToken, $redirectUrl = null, ?string $oauthTokenSecret = null): SignInResult
888 580
    {
889 581
        $provider = $provider instanceof Provider ? (string) $provider : $provider;
@@ -910,13 +602,6 @@
Loading
910 602
        return $this->signInHandler->handle($action);
911 603
    }
912 604
913 -
    /**
914 -
     * @param Provider|string $provider
915 -
     * @param Token|string $idToken
916 -
     * @param UriInterface|string|null $redirectUrl
917 -
     *
918 -
     * @throws FailedToSignIn
919 -
     */
920 605
    public function signInWithIdpIdToken($provider, $idToken, $redirectUrl = null): SignInResult
921 606
    {
922 607
        $provider = $provider instanceof Provider ? (string) $provider : $provider;

@@ -4,9 +4,7 @@
Loading
4 4
5 5
namespace Kreait\Firebase;
6 6
7 -
use Kreait\Firebase\Exception\RemoteConfig\ValidationFailed;
8 7
use Kreait\Firebase\Exception\RemoteConfig\VersionNotFound;
9 -
use Kreait\Firebase\Exception\RemoteConfigException;
10 8
use Kreait\Firebase\RemoteConfig\ApiClient;
11 9
use Kreait\Firebase\RemoteConfig\FindVersions;
12 10
use Kreait\Firebase\RemoteConfig\Template;
@@ -16,13 +14,7 @@
Loading
16 14
use Psr\Http\Message\ResponseInterface;
17 15
use Traversable;
18 16
19 -
/**
20 -
 * The Firebase Remote Config.
21 -
 *
22 -
 * @see https://firebase.google.com/docs/remote-config/use-config-rest
23 -
 * @see https://firebase.google.com/docs/remote-config/rest-reference
24 -
 */
25 -
class RemoteConfig
17 +
class RemoteConfig implements Contract\RemoteConfig
26 18
{
27 19
    /** @var ApiClient */
28 20
    private $client;
@@ -35,34 +27,16 @@
Loading
35 27
        $this->client = $client;
36 28
    }
37 29
38 -
    /**
39 -
     * @throws RemoteConfigException if something went wrong
40 -
     */
41 30
    public function get(): Template
42 31
    {
43 32
        return $this->buildTemplateFromResponse($this->client->getTemplate());
44 33
    }
45 34
46 -
    /**
47 -
     * Validates the given template without publishing it.
48 -
     *
49 -
     * @param Template|array<string, mixed> $template
50 -
     *
51 -
     * @throws ValidationFailed if the validation failed
52 -
     * @throws RemoteConfigException
53 -
     */
54 35
    public function validate($template): void
55 36
    {
56 37
        $this->client->validateTemplate($this->ensureTemplate($template));
57 38
    }
58 39
59 -
    /**
60 -
     * @param Template|array<string, mixed> $template
61 -
     *
62 -
     * @throws RemoteConfigException
63 -
     *
64 -
     * @return string The etag value of the published template that can be compared to in later calls
65 -
     */
66 40
    public function publish($template): string
67 41
    {
68 42
        $etag = $this->client
@@ -72,14 +46,6 @@
Loading
72 46
        return \array_shift($etag) ?: '';
73 47
    }
74 48
75 -
    /**
76 -
     * Returns a version with the given number.
77 -
     *
78 -
     * @param VersionNumber|int|string $versionNumber
79 -
     *
80 -
     * @throws VersionNotFound
81 -
     * @throws RemoteConfigException if something went wrong
82 -
     */
83 49
    public function getVersion($versionNumber): Version
84 50
    {
85 51
        $versionNumber = $this->ensureVersionNumber($versionNumber);
@@ -93,14 +59,6 @@
Loading
93 59
        throw VersionNotFound::withVersionNumber($versionNumber);
94 60
    }
95 61
96 -
    /**
97 -
     * Returns a version with the given number.
98 -
     *
99 -
     * @param VersionNumber|int|string $versionNumber
100 -
     *
101 -
     * @throws VersionNotFound
102 -
     * @throws RemoteConfigException if something went wrong
103 -
     */
104 62
    public function rollbackToVersion($versionNumber): Template
105 63
    {
106 64
        $versionNumber = $this->ensureVersionNumber($versionNumber);
@@ -108,13 +66,6 @@
Loading
108 66
        return $this->buildTemplateFromResponse($this->client->rollbackToVersion($versionNumber));
109 67
    }
110 68
111 -
    /**
112 -
     * @param FindVersions|array<string, mixed>|null $query
113 -
     *
114 -
     * @throws RemoteConfigException if something went wrong
115 -
     *
116 -
     * @return Traversable<Version>|Version[]
117 -
     */
118 69
    public function listVersions($query = null): Traversable
119 70
    {
120 71
        $query = $query instanceof FindVersions ? $query : FindVersions::fromArray((array) $query);

@@ -9,17 +9,10 @@
Loading
9 9
use Kreait\Firebase\Database\Reference;
10 10
use Kreait\Firebase\Database\RuleSet;
11 11
use Kreait\Firebase\Database\Transaction;
12 -
use Kreait\Firebase\Exception\DatabaseException;
13 12
use Kreait\Firebase\Exception\InvalidArgumentException;
14 -
use Kreait\Firebase\Exception\OutOfRangeException;
15 13
use Psr\Http\Message\UriInterface;
16 14
17 -
/**
18 -
 * The Firebase Realtime Database.
19 -
 *
20 -
 * @see https://firebase.google.com/docs/reference/js/firebase.database.Database
21 -
 */
22 -
class Database
15 +
class Database implements Contract\Database
23 16
{
24 17
    public const SERVER_TIMESTAMP = ['.sv' => 'timestamp'];
25 18
@@ -38,13 +31,6 @@
Loading
38 31
        $this->client = $client;
39 32
    }
40 33
41 -
    /**
42 -
     * Returns a Reference to the root or the specified path.
43 -
     *
44 -
     * @see https://firebase.google.com/docs/reference/js/firebase.database.Database#ref
45 -
     *
46 -
     * @throws InvalidArgumentException
47 -
     */
48 34
    public function getReference(?string $path = null): Reference
49 35
    {
50 36
        if ($path === null || \trim($path) === '') {
@@ -58,16 +44,6 @@
Loading
58 44
        }
59 45
    }
60 46
61 -
    /**
62 -
     * Returns a reference to the root or the path specified in url.
63 -
     *
64 -
     * @see https://firebase.google.com/docs/reference/js/firebase.database.Database#refFromURL
65 -
     *
66 -
     * @param string|UriInterface $uri
67 -
     *
68 -
     * @throws InvalidArgumentException If the URL is invalid
69 -
     * @throws OutOfRangeException If the URL is not in the same domain as the current database
70 -
     */
71 47
    public function getReferenceFromUrl($uri): Reference
72 48
    {
73 49
        $uri = $uri instanceof UriInterface ? $uri : new Uri($uri);
@@ -82,13 +58,6 @@
Loading
82 58
        return $this->getReference($uri->getPath());
83 59
    }
84 60
85 -
    /**
86 -
     * Retrieve Firebase Database Rules.
87 -
     *
88 -
     * @see https://firebase.google.com/docs/database/rest/app-management#retrieving-firebase-realtime-database-rules
89 -
     *
90 -
     * @throws DatabaseException
91 -
     */
92 61
    public function getRuleSet(): RuleSet
93 62
    {
94 63
        $rules = $this->client->get($this->uri->withPath('.settings/rules'));
@@ -96,21 +65,11 @@
Loading
96 65
        return RuleSet::fromArray($rules);
97 66
    }
98 67
99 -
    /**
100 -
     * Update Firebase Database Rules.
101 -
     *
102 -
     * @see https://firebase.google.com/docs/database/rest/app-management#updating-firebase-realtime-database-rules
103 -
     *
104 -
     * @throws DatabaseException
105 -
     */
106 68
    public function updateRules(RuleSet $ruleSet): void
107 69
    {
108 70
        $this->client->updateRules($this->uri->withPath('.settings/rules'), $ruleSet);
109 71
    }
110 72
111 -
    /**
112 -
     * @return mixed
113 -
     */
114 73
    public function runTransaction(callable $callable)
115 74
    {
116 75
        $transaction = new Transaction($this->client);

@@ -6,7 +6,7 @@
Loading
6 6
7 7
use Google\Cloud\Firestore\FirestoreClient;
8 8
9 -
final class Firestore
9 +
final class Firestore implements Contract\Firestore
10 10
{
11 11
    /** @var FirestoreClient */
12 12
    private $client;

@@ -403,7 +403,7 @@
Loading
403 403
        return null;
404 404
    }
405 405
406 -
    public function createAuth(): Auth
406 +
    public function createAuth(): Contract\Auth
407 407
    {
408 408
        $http = $this->createApiClient([
409 409
            'base_uri' => 'https://www.googleapis.com/identitytoolkit/v3/relyingparty/',
@@ -462,7 +462,7 @@
Loading
462 462
        return new IdTokenVerifier($baseVerifier, $this->clock);
463 463
    }
464 464
465 -
    public function createDatabase(): Database
465 +
    public function createDatabase(): Contract\Database
466 466
    {
467 467
        $http = $this->createApiClient();
468 468
@@ -473,7 +473,7 @@
Loading
473 473
        return new Database($this->getDatabaseUri(), new Database\ApiClient($http));
474 474
    }
475 475
476 -
    public function createRemoteConfig(): RemoteConfig
476 +
    public function createRemoteConfig(): Contract\RemoteConfig
477 477
    {
478 478
        if (!($projectId = $this->getProjectId())) {
479 479
            throw new RuntimeException('Unable to create the messaging service without a project ID');
@@ -486,7 +486,7 @@
Loading
486 486
        return new RemoteConfig(new RemoteConfig\ApiClient($http));
487 487
    }
488 488
489 -
    public function createMessaging(): Messaging
489 +
    public function createMessaging(): Contract\Messaging
490 490
    {
491 491
        if (!($projectId = $this->getProjectId())) {
492 492
            throw new RuntimeException('Unable to create the messaging service without a project ID');
@@ -517,7 +517,7 @@
Loading
517 517
    /**
518 518
     * @param string|Url|UriInterface|mixed $defaultDynamicLinksDomain
519 519
     */
520 -
    public function createDynamicLinksService($defaultDynamicLinksDomain = null): DynamicLinks
520 +
    public function createDynamicLinksService($defaultDynamicLinksDomain = null): Contract\DynamicLinks
521 521
    {
522 522
        $apiClient = $this->createApiClient();
523 523
@@ -528,7 +528,7 @@
Loading
528 528
        return DynamicLinks::withApiClient($apiClient);
529 529
    }
530 530
531 -
    public function createFirestore(): Firestore
531 +
    public function createFirestore(): Contract\Firestore
532 532
    {
533 533
        $config = [];
534 534
@@ -556,7 +556,7 @@
Loading
556 556
        return Firestore::withFirestoreClient($firestoreClient);
557 557
    }
558 558
559 -
    public function createStorage(): Storage
559 +
    public function createStorage(): Contract\Storage
560 560
    {
561 561
        $config = [];
562 562

@@ -5,10 +5,8 @@
Loading
5 5
namespace Kreait\Firebase;
6 6
7 7
use GuzzleHttp\Promise\Utils;
8 -
use Kreait\Firebase\Exception\FirebaseException;
9 8
use Kreait\Firebase\Exception\InvalidArgumentException;
10 9
use Kreait\Firebase\Exception\Messaging\InvalidArgument;
11 -
use Kreait\Firebase\Exception\Messaging\InvalidMessage;
12 10
use Kreait\Firebase\Exception\Messaging\NotFound;
13 11
use Kreait\Firebase\Exception\MessagingException;
14 12
use Kreait\Firebase\Http\ResponseWithSubResponses;
@@ -28,7 +26,7 @@
Loading
28 26
use Kreait\Firebase\Project\ProjectId;
29 27
use Kreait\Firebase\Util\JSON;
30 28
31 -
class Messaging
29 +
class Messaging implements Contract\Messaging
32 30
{
33 31
    /** @var string */
34 32
    private $projectId;
@@ -49,15 +47,6 @@
Loading
49 47
        $this->projectId = $projectId->value();
50 48
    }
51 49
52 -
    /**
53 -
     * @param Message|array<string, mixed> $message
54 -
     *
55 -
     * @throws InvalidArgumentException
56 -
     * @throws MessagingException
57 -
     * @throws FirebaseException
58 -
     *
59 -
     * @return array<mixed>
60 -
     */
61 50
    public function send($message, bool $validateOnly = false): array
62 51
    {
63 52
        $message = $this->makeMessage($message);
@@ -78,14 +67,6 @@
Loading
78 67
        return JSON::decode((string) $response->getBody(), true);
79 68
    }
80 69
81 -
    /**
82 -
     * @param Message|array<string, mixed> $message
83 -
     * @param RegistrationTokens|RegistrationToken|RegistrationToken[]|string[]|string $registrationTokens
84 -
     *
85 -
     * @throws InvalidArgumentException if the message is invalid
86 -
     * @throws MessagingException if the API request failed
87 -
     * @throws FirebaseException if something very unexpected happened (never :))
88 -
     */
89 70
    public function sendMulticast($message, $registrationTokens, bool $validateOnly = false): MulticastSendReport
90 71
    {
91 72
        $message = $this->makeMessage($message);
@@ -98,13 +79,6 @@
Loading
98 79
        return MulticastSendReport::fromRequestsAndResponses($request->subRequests(), $response->subResponses());
99 80
    }
100 81
101 -
    /**
102 -
     * @param array[]|Message[]|Messages $messages
103 -
     *
104 -
     * @throws InvalidArgumentException if the message is invalid
105 -
     * @throws MessagingException if the API request failed
106 -
     * @throws FirebaseException if something very unexpected happened (never :))
107 -
     */
108 82
    public function sendAll($messages, bool $validateOnly = false): MulticastSendReport
109 83
    {
110 84
        $ensuredMessages = [];
@@ -120,29 +94,11 @@
Loading
120 94
        return MulticastSendReport::fromRequestsAndResponses($request->subRequests(), $response->subResponses());
121 95
    }
122 96
123 -
    /**
124 -
     * @param Message|array<string, mixed> $message
125 -
     *
126 -
     * @throws InvalidArgumentException
127 -
     * @throws InvalidMessage
128 -
     * @throws MessagingException
129 -
     * @throws FirebaseException
130 -
     *
131 -
     * @return array<mixed>
132 -
     */
133 97
    public function validate($message): array
134 98
    {
135 99
        return $this->send($message, true);
136 100
    }
137 101
138 -
    /**
139 -
     * @param RegistrationTokens|RegistrationToken|RegistrationToken[]|string[]|string $registrationTokenOrTokens
140 -
     *
141 -
     * @throws FirebaseException
142 -
     * @throws MessagingException
143 -
     *
144 -
     * @return array<string, array<int, string>>
145 -
     */
146 102
    public function validateRegistrationTokens($registrationTokenOrTokens): array
147 103
    {
148 104
        $registrationTokenOrTokens = $this->ensureNonEmptyRegistrationTokens($registrationTokenOrTokens);
@@ -156,23 +112,11 @@
Loading
156 112
        ];
157 113
    }
158 114
159 -
    /**
160 -
     * @param string|Topic $topic
161 -
     * @param mixed $registrationTokenOrTokens
162 -
     *
163 -
     * @return array<string, array<string, string>>
164 -
     */
165 115
    public function subscribeToTopic($topic, $registrationTokenOrTokens): array
166 116
    {
167 117
        return $this->subscribeToTopics([$topic], $registrationTokenOrTokens);
168 118
    }
169 119
170 -
    /**
171 -
     * @param iterable<string|Topic> $topics
172 -
     * @param RegistrationTokens|RegistrationToken|RegistrationToken[]|string[]|string $registrationTokenOrTokens
173 -
     *
174 -
     * @return array<string, array<string, string>>
175 -
     */
176 120
    public function subscribeToTopics(iterable $topics, $registrationTokenOrTokens): array
177 121
    {
178 122
        $topicObjects = [];
@@ -186,23 +130,11 @@
Loading
186 130
        return $this->appInstanceApi->subscribeToTopics($topicObjects, $tokens);
187 131
    }
188 132
189 -
    /**
190 -
     * @param string|Topic $topic
191 -
     * @param mixed $registrationTokenOrTokens
192 -
     *
193 -
     * @return array<string, array<string, string>>
194 -
     */
195 133
    public function unsubscribeFromTopic($topic, $registrationTokenOrTokens): array
196 134
    {
197 135
        return $this->unsubscribeFromTopics([$topic], $registrationTokenOrTokens);
198 136
    }
199 137
200 -
    /**
201 -
     * @param array<string|Topic> $topics
202 -
     * @param RegistrationTokens|RegistrationToken|RegistrationToken[]|string[]|string $registrationTokenOrTokens
203 -
     *
204 -
     * @return array<string, array<string, string>>
205 -
     */
206 138
    public function unsubscribeFromTopics(array $topics, $registrationTokenOrTokens): array
207 139
    {
208 140
        $topics = \array_map(static function ($topic) {
@@ -214,11 +146,6 @@
Loading
214 146
        return $this->appInstanceApi->unsubscribeFromTopics($topics, $tokens);
215 147
    }
216 148
217 -
    /**
218 -
     * @param RegistrationTokens|RegistrationToken|RegistrationToken[]|string[]|string $registrationTokenOrTokens
219 -
     *
220 -
     * @return array<string, array<string, string>>
221 -
     */
222 149
    public function unsubscribeFromAllTopics($registrationTokenOrTokens): array
223 150
    {
224 151
        $tokens = $this->ensureNonEmptyRegistrationTokens($registrationTokenOrTokens);
@@ -251,14 +178,6 @@
Loading
251 178
        return $result;
252 179
    }
253 180
254 -
    /**
255 -
     * @see https://developers.google.com/instance-id/reference/server#results
256 -
     *
257 -
     * @param RegistrationToken|string $registrationToken
258 -
     *
259 -
     * @throws InvalidArgument if the registration token is invalid
260 -
     * @throws FirebaseException
261 -
     */
262 181
    public function getAppInstance($registrationToken): AppInstance
263 182
    {
264 183
        $token = $registrationToken instanceof RegistrationToken
Files Complexity Coverage
src/Firebase 1,547 92.56%
Project Totals (150 files) 1547 92.56%
1
comment:
2
  layout: "reach,diff"
3

4
coverage:
5
  status:
6
    project:
7
      default:
8
        informational: true
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading