kreait / firebase-php

@@ -0,0 +1,53 @@
Loading
1 +
<?php
2 +
3 +
declare(strict_types=1);
4 +
5 +
namespace Kreait\Firebase\Exception\Database;
6 +
7 +
use Kreait\Firebase\Exception\DatabaseException;
8 +
use LogicException;
9 +
use Psr\Http\Message\UriInterface;
10 +
11 +
final class DatabaseNotFound extends LogicException implements DatabaseException
12 +
{
13 +
    public static function fromUri(UriInterface $uri): self
14 +
    {
15 +
        $scheme = $uri->getScheme();
16 +
        $host = $uri->getHost();
17 +
18 +
        $databaseName = \explode('.', $host, 2)[0] ?? '';
19 +
20 +
        $databaseUri = "{$scheme}://{$host}";
21 +
        $suggestedDatabaseUri = \str_replace($databaseName, $databaseName.'-default-rtdb', $databaseUri);
22 +
23 +
        $message = <<<MESSAGE
24 +
25 +
26 +
The database at
27 +
28 +
    $databaseUri
29 +
30 +
could not be found. You can find the correct name at
31 +
32 +
    https://console.firebase.google.com/project/_/database
33 +
34 +
If you haven't configured the SDK otherwise and if you don't use multiple
35 +
Realtime Databases, the name you will find will most likely be
36 +
37 +
    $suggestedDatabaseUri
38 +
39 +
The reason for this is that during the lifetime of the Firebase Admin SDK,
40 +
Firebase has changed the name of the default database. Previously, the default
41 +
database had the same identifier as the project. Since approximately September
42 +
2020, Realtime Databases in newly created projects have the '-default-rtdb'
43 +
suffix.
44 +
45 +
For instructions on how to set the name of the used Realtime Database, please
46 +
see https://firebase-php.readthedocs.io/en/5.x/#quick-start
47 +
48 +
49 +
MESSAGE;
50 +
51 +
        return new self($message);
52 +
    }
53 +
}

@@ -57,6 +57,8 @@
Loading
57 57
                return new Database\PermissionDenied($message, $code, $e);
58 58
            case StatusCode::STATUS_PRECONDITION_FAILED:
59 59
                return new Database\PreconditionFailed($message, $code, $e);
60 +
            case StatusCode::STATUS_NOT_FOUND:
61 +
                return Database\DatabaseNotFound::fromUri($e->getRequest()->getUri());
60 62
        }
61 63
62 64
        return new DatabaseError($message, $code, $e);

@@ -6,6 +6,7 @@
Loading
6 6
7 7
use Kreait\Firebase\Database\Query\Filter;
8 8
use Kreait\Firebase\Database\Query\Sorter;
9 +
use Kreait\Firebase\Exception\Database\DatabaseNotFound;
9 10
use Kreait\Firebase\Exception\Database\UnsupportedQuery;
10 11
use Kreait\Firebase\Exception\DatabaseException;
11 12
use Psr\Http\Message\UriInterface;
@@ -66,6 +67,8 @@
Loading
66 67
    {
67 68
        try {
68 69
            $value = $this->apiClient->get($this->getUri());
70 +
        } catch (DatabaseNotFound $e) {
71 +
            throw $e;
69 72
        } catch (DatabaseException $e) {
70 73
            throw new UnsupportedQuery($this, $e->getMessage(), $e->getCode(), $e->getPrevious());
71 74
        }
Files Complexity Coverage
src/Firebase 1,543 92.56%
Project Totals (150 files) 1543 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