kreait / firebase-php

Compare 1cd750c ... +2 ... 2e52fd2

Coverage Reach
Auth/SignIn/GuzzleHandler.php Auth/SignIn/FailedToSignIn.php Auth/IdTokenVerifier.php Auth/ApiClient.php Auth/ActionCodeSettings/ValidatedActionCodeSettings.php Auth/ActionCodeSettings/RawActionCodeSettings.php Auth/CreateActionLink/GuzzleApiClientHandler.php Auth/CreateActionLink/FailedToCreateActionLink.php Auth/CreateActionLink/ApiRequest.php Auth/UserRecord.php Auth/SendActionLink/FailedToSendActionLink.php Auth/SendActionLink/ApiRequest.php Auth/SendActionLink/GuzzleApiClientHandler.php Auth/SignInResult.php Auth/SignInWithIdpCredentials.php Auth/CustomTokenViaGoogleIam.php Auth/SendActionLink.php Auth/CreateActionLink.php Auth/UserMetaData.php Auth/UserInfo.php Auth/SignInWithEmailAndOobCode.php Auth/SignInWithEmailAndPassword.php Auth/SignInWithRefreshToken.php Auth/SignInWithCustomToken.php Auth/DisabledLegacyIdTokenVerifier.php Auth/DisabledLegacyCustomTokenGenerator.php Auth/SignInAnonymously.php Messaging/AppInstanceApiClient.php Messaging/CloudMessage.php Messaging/MulticastSendReport.php Messaging/Notification.php Messaging/Http/Request/SendMessages.php Messaging/Http/Request/SendMessageToTokens.php Messaging/Http/Request/ValidateMessage.php Messaging/Http/Request/SendMessage.php Messaging/RegistrationTokens.php Messaging/SendReport.php Messaging/AppInstance.php Messaging/MessageTarget.php Messaging/MessageData.php Messaging/Condition.php Messaging/TopicSubscription.php Messaging/Topic.php Messaging/FcmOptions.php Messaging/ApiClient.php Messaging/RegistrationToken.php Messaging/ApnsConfig.php Messaging/AndroidConfig.php Messaging/WebPushConfig.php Messaging/TopicSubscriptions.php Messaging/Messages.php Messaging/RawMessageFromArray.php DynamicLink/AnalyticsInfo/GooglePlayAnalytics.php DynamicLink/AnalyticsInfo/ITunesConnectAnalytics.php DynamicLink/CreateDynamicLink.php DynamicLink/IOSInfo.php DynamicLink/EventStatistics.php DynamicLink/CreateDynamicLink/FailedToCreateDynamicLink.php DynamicLink/CreateDynamicLink/GuzzleApiClientHandler.php DynamicLink/CreateDynamicLink/ApiRequest.php DynamicLink/ShortenLongDynamicLink/FailedToShortenLongDynamicLink.php DynamicLink/ShortenLongDynamicLink/GuzzleApiClientHandler.php DynamicLink/ShortenLongDynamicLink/ApiRequest.php DynamicLink/GetStatisticsForDynamicLink/GuzzleApiClientHandler.php DynamicLink/GetStatisticsForDynamicLink/FailedToGetStatisticsForDynamicLink.php DynamicLink/GetStatisticsForDynamicLink/ApiRequest.php DynamicLink/SocialMetaTagInfo.php DynamicLink/AndroidInfo.php DynamicLink/ShortenLongDynamicLink.php DynamicLink/AnalyticsInfo.php DynamicLink/NavigationInfo.php DynamicLink/GetStatisticsForDynamicLink.php DynamicLink/DynamicLinkStatistics.php RemoteConfig/Template.php RemoteConfig/FindVersions.php RemoteConfig/ApiClient.php RemoteConfig/Parameter.php RemoteConfig/Condition.php RemoteConfig/Version.php RemoteConfig/ParameterGroup.php RemoteConfig/ConditionalValue.php RemoteConfig/VersionNumber.php RemoteConfig/DefaultValue.php RemoteConfig/User.php RemoteConfig/TagColor.php RemoteConfig/UpdateType.php RemoteConfig/UpdateOrigin.php Database/Reference.php Database/Query/Filter/EndAt.php Database/Query/Filter/EqualTo.php Database/Query/Filter/StartAt.php Database/Query/Filter/LimitToLast.php Database/Query/Filter/LimitToFirst.php Database/Query/Filter/Shallow.php Database/Query/Sorter/OrderByChild.php Database/Query/Sorter/OrderByKey.php Database/Query/Sorter/OrderByValue.php Database/Query.php Database/ApiClient.php Database/Reference/Validator.php Database/Snapshot.php Database/Transaction.php Database/RuleSet.php Factory.php Auth.php Exception/AuthApiExceptionConverter.php Exception/MessagingApiExceptionConverter.php Exception/Database/TransactionFailed.php Exception/Database/ReferenceHasNotBeenSnapshotted.php Exception/Database/UnsupportedQuery.php Exception/Messaging/ServerUnavailable.php Exception/Messaging/AuthenticationError.php Exception/Messaging/InvalidMessage.php Exception/Messaging/MessagingError.php Exception/Messaging/NotFound.php Exception/Messaging/ServerError.php Exception/RemoteConfigApiExceptionConverter.php Exception/DatabaseApiExceptionConverter.php Exception/Auth/RevokedIdToken.php Exception/RemoteConfig/VersionNotFound.php Http/ResponseWithSubResponses.php Http/HttpClientOptions.php Http/Middleware.php Http/RequestWithSubRequests.php Http/ErrorResponseParser.php Http/Requests.php Http/Responses.php Request/UpdateUser.php Request/CreateUser.php Messaging.php Value/Url.php Value/PhoneNumber.php Value/Email.php Value/ClearTextPassword.php Value/Uid.php Value/Provider.php DynamicLinks.php Util/DT.php Util/JSON.php Util/Deprecation.php ServiceAccount.php RemoteConfig.php Database.php DynamicLink.php Storage.php Project/ProjectId.php Firestore.php Util.php

Flags

Flags have been temporarily removed from this view while the flagging feature is refactored for better performance and user experience.

You can still use flags when viewing individual files. Flag-level thresholds will also remain on pull and merge requests in your repository provider.

More information can be found in our documentation.


@@ -12,9 +12,7 @@
Loading
12 12
    public const TOKEN = 'token';
13 13
    public const TOPIC = 'topic';
14 14
15 -
    /**
16 -
     * @internal
17 -
     */
15 +
    /** @internal */
18 16
    public const UNKNOWN = 'unknown';
19 17
20 18
    public const TYPES = [

@@ -44,6 +44,11 @@
Loading
44 44
        return $this->name;
45 45
    }
46 46
47 +
    public function expression(): string
48 +
    {
49 +
        return $this->expression;
50 +
    }
51 +
47 52
    public function withExpression(string $expression): self
48 53
    {
49 54
        $condition = clone $this;

@@ -7,7 +7,6 @@
Loading
7 7
use Kreait\Firebase\Exception\InvalidArgumentException;
8 8
use Kreait\Firebase\Util\JSON;
9 9
use Psr\Http\Message\ResponseInterface;
10 -
use Throwable;
11 10
12 11
class Template implements \JsonSerializable
13 12
{
@@ -17,6 +16,9 @@
Loading
17 16
    /** @var Parameter[] */
18 17
    private $parameters = [];
19 18
19 +
    /** @var ParameterGroup[] */
20 +
    private $parameterGroups = [];
21 +
20 22
    /** @var Condition[] */
21 23
    private $conditions = [];
22 24
@@ -29,15 +31,14 @@
Loading
29 31
30 32
    public static function new(): self
31 33
    {
32 -
        $template = new self();
33 -
        $template->etag = '*';
34 -
        $template->parameters = [];
35 -
36 -
        return $template;
34 +
        return new self();
37 35
    }
38 36
39 37
    /**
40 38
     * @internal
39 +
     *
40 +
     * @deprecated 5.10.0
41 +
     * @codeCoverageIgnore
41 42
     */
42 43
    public static function fromResponse(ResponseInterface $response): self
43 44
    {
@@ -57,24 +58,69 @@
Loading
57 58
        $template->etag = $etag ?? '*';
58 59
59 60
        foreach ((array) ($data['conditions'] ?? []) as $conditionData) {
60 -
            $template->conditions[(string) $conditionData['name']] = Condition::fromArray($conditionData);
61 +
            $template = $template->withCondition(self::buildCondition($conditionData['name'], $conditionData));
61 62
        }
62 63
63 64
        foreach ((array) ($data['parameters'] ?? []) as $name => $parameterData) {
64 -
            $template->parameters[(string) $name] = Parameter::fromArray([(string) $name => $parameterData]);
65 +
            $template = $template->withParameter(self::buildParameter($name, $parameterData));
66 +
        }
67 +
68 +
        foreach ((array) ($data['parameterGroups'] ?? []) as $name => $parameterGroupData) {
69 +
            $template = $template->withParameterGroup(self::buildParameterGroup($name, $parameterGroupData));
65 70
        }
66 71
67 72
        if (\is_array($data['version'] ?? null)) {
68 -
            try {
69 -
                $template->version = Version::fromArray($data['version']);
70 -
            } catch (Throwable $e) {
71 -
                $template->version = null;
72 -
            }
73 +
            $template->version = Version::fromArray($data['version']);
73 74
        }
74 75
75 76
        return $template;
76 77
    }
77 78
79 +
    /**
80 +
     * @param array<string, string> $data
81 +
     */
82 +
    private static function buildCondition(string $name, array $data): Condition
83 +
    {
84 +
        $condition = Condition::named($name)->withExpression($data['expression']);
85 +
86 +
        if ($tagColor = $data['tagColor'] ?? null) {
87 +
            $condition = $condition->withTagColor(new TagColor($tagColor));
88 +
        }
89 +
90 +
        return $condition;
91 +
    }
92 +
93 +
    /**
94 +
     * @param array<string, mixed> $data
95 +
     */
96 +
    private static function buildParameter(string $name, array $data): Parameter
97 +
    {
98 +
        $parameter = Parameter::named($name)
99 +
            ->withDescription((string) ($data['description'] ?? ''))
100 +
            ->withDefaultValue(DefaultValue::fromArray($data['defaultValue'] ?? []));
101 +
102 +
        foreach ((array) ($data['conditionalValues'] ?? []) as $key => $conditionalValueData) {
103 +
            $parameter = $parameter->withConditionalValue(new ConditionalValue($key, $conditionalValueData['value']));
104 +
        }
105 +
106 +
        return $parameter;
107 +
    }
108 +
109 +
    /**
110 +
     * @param array<string, mixed> $parameterGroupData
111 +
     */
112 +
    private static function buildParameterGroup(string $name, array $parameterGroupData): ParameterGroup
113 +
    {
114 +
        $group = ParameterGroup::named($name)
115 +
            ->withDescription((string) ($parameterGroupData['description'] ?? ''));
116 +
117 +
        foreach ($parameterGroupData['parameters'] ?? [] as $parameterName => $parameterData) {
118 +
            $group = $group->withParameter(self::buildParameter($parameterName, $parameterData));
119 +
        }
120 +
121 +
        return $group;
122 +
    }
123 +
78 124
    /**
79 125
     * @internal
80 126
     */
@@ -83,6 +129,14 @@
Loading
83 129
        return $this->etag;
84 130
    }
85 131
132 +
    /**
133 +
     * @return Condition[]
134 +
     */
135 +
    public function conditions(): array
136 +
    {
137 +
        return $this->conditions;
138 +
    }
139 +
86 140
    /**
87 141
     * @return Parameter[]
88 142
     */
@@ -91,6 +145,14 @@
Loading
91 145
        return $this->parameters;
92 146
    }
93 147
148 +
    /**
149 +
     * @return ParameterGroup[]
150 +
     */
151 +
    public function parameterGroups(): array
152 +
    {
153 +
        return $this->parameterGroups;
154 +
    }
155 +
94 156
    public function version(): ?Version
95 157
    {
96 158
        return $this->version;
@@ -106,6 +168,14 @@
Loading
106 168
        return $template;
107 169
    }
108 170
171 +
    public function withParameterGroup(ParameterGroup $parameterGroup): Template
172 +
    {
173 +
        $template = clone $this;
174 +
        $template->parameterGroups[$parameterGroup->name()] = $parameterGroup;
175 +
176 +
        return $template;
177 +
    }
178 +
109 179
    public function withCondition(Condition $condition): Template
110 180
    {
111 181
        $template = clone $this;
@@ -118,7 +188,7 @@
Loading
118 188
    {
119 189
        foreach ($parameter->conditionalValues() as $conditionalValue) {
120 190
            if (!\array_key_exists($conditionalValue->conditionName(), $this->conditions)) {
121 -
                $message = 'The conditional value of the parameter named "%s" referes to a condition "%s" which does not exist.';
191 +
                $message = 'The conditional value of the parameter named "%s" refers to a condition "%s" which does not exist.';
122 192
123 193
                throw new InvalidArgumentException(\sprintf($message, $parameter->name(), $conditionalValue->conditionName()));
124 194
            }
@@ -130,11 +200,10 @@
Loading
130 200
     */
131 201
    public function jsonSerialize(): array
132 202
    {
133 -
        $result = [
134 -
            'conditions' => \array_values($this->conditions),
135 -
            'parameters' => $this->parameters,
203 +
        return [
204 +
            'conditions' => !empty($this->conditions) ? \array_values($this->conditions) : null,
205 +
            'parameters' => !empty($this->parameters) ? $this->parameters : null,
206 +
            'parameterGroups' => !empty($this->parameterGroups) ? $this->parameterGroups : null,
136 207
        ];
137 -
138 -
        return \array_filter($result);
139 208
    }
140 209
}

@@ -92,6 +92,9 @@
Loading
92 92
    }
93 93
94 94
    /**
95 +
     * @deprecated 5.10.0
96 +
     * @codeCoverageIgnore
97 +
     *
95 98
     * @param array<string, mixed> $data
96 99
     */
97 100
    public static function fromArray(array $data): self

@@ -0,0 +1,71 @@
Loading
1 +
<?php
2 +
3 +
declare(strict_types=1);
4 +
5 +
namespace Kreait\Firebase\RemoteConfig;
6 +
7 +
final class ParameterGroup implements \JsonSerializable
8 +
{
9 +
    /** @var string */
10 +
    private $name;
11 +
12 +
    /** @var string */
13 +
    private $description = '';
14 +
15 +
    /** @var Parameter[] */
16 +
    private $parameters = [];
17 +
18 +
    private function __construct()
19 +
    {
20 +
    }
21 +
22 +
    public static function named(string $name): self
23 +
    {
24 +
        $group = new self();
25 +
        $group->name = $name;
26 +
27 +
        return $group;
28 +
    }
29 +
30 +
    public function name(): string
31 +
    {
32 +
        return $this->name;
33 +
    }
34 +
35 +
    public function description(): string
36 +
    {
37 +
        return $this->description;
38 +
    }
39 +
40 +
    /**
41 +
     * @return Parameter[]
42 +
     */
43 +
    public function parameters(): array
44 +
    {
45 +
        return $this->parameters;
46 +
    }
47 +
48 +
    public function withDescription(string $description): self
49 +
    {
50 +
        $group = clone $this;
51 +
        $group->description = $description;
52 +
53 +
        return $group;
54 +
    }
55 +
56 +
    public function withParameter(Parameter $parameter): self
57 +
    {
58 +
        $group = clone $this;
59 +
        $group->parameters[$parameter->name()] = $parameter;
60 +
61 +
        return $group;
62 +
    }
63 +
64 +
    public function jsonSerialize()
65 +
    {
66 +
        return [
67 +
            'description' => $this->description,
68 +
            'parameters' => $this->parameters,
69 +
        ];
70 +
    }
71 +
}

Click to load this diff.
Loading diff...

Learn more Showing 62 files with coverage changes found.

Changes in src/Firebase/Http/Responses.php
-2
+2
Loading file...
Changes in src/Firebase/Auth/SignInWithEmailAndOobCode.php
-10
+10
Loading file...
Changes in src/Firebase/Http/RequestWithSubRequests.php
-31
+31
Loading file...
Changes in src/Firebase/Auth/SignInWithCustomToken.php
-7
+7
Loading file...
Changes in src/Firebase/Auth/SignInWithIdpCredentials.php
-29
+29
Loading file...
Changes in src/Firebase/Auth/SignInWithEmailAndPassword.php
-10
+10
Loading file...
Changes in src/Firebase/Exception/RemoteConfig/VersionNotFound.php
-2
+2
Loading file...
Changes in src/Firebase/Auth/SignInWithRefreshToken.php
-7
+7
Loading file...
Changes in src/Firebase/Http/Requests.php
-5
+5
Loading file...
Changes in src/Firebase/Messaging/RawMessageFromArray.php
-4
+4
Loading file...
Changes in src/Firebase/Messaging/TopicSubscriptions.php
-6
+6
Loading file...
Changes in src/Firebase/Firestore.php
-7
+7
Loading file...
Changes in src/Firebase/RemoteConfig/FindVersions.php
-45
+45
Loading file...
Changes in src/Firebase/Messaging/SendReport.php
-26
+26
Loading file...
Changes in src/Firebase/Messaging/MulticastSendReport.php
-58
+58
Loading file...
Changes in src/Firebase/Messaging/AppInstance.php
-22
+22
Loading file...
Changes in src/Firebase/Http/ResponseWithSubResponses.php
-30
+30
Loading file...
Changes in src/Firebase/Messaging/AppInstanceApiClient.php
-60
+60
Loading file...
Changes in src/Firebase/RemoteConfig/VersionNumber.php
-11
+11
Loading file...
Changes in src/Firebase/Auth/CustomTokenViaGoogleIam.php
-22
+22
Loading file...
Changes in src/Firebase/Auth/UserRecord.php
-28
+28
Loading file...
Changes in src/Firebase/Messaging/Http/Request/SendMessages.php
-10
+10
Loading file...
Changes in src/Firebase/RemoteConfig/Version.php
-23
+23
Loading file...
Changes in src/Firebase/RemoteConfig/ApiClient.php
-31
+31
Loading file...
Changes in src/Firebase/Messaging/Http/Request/SendMessageToTokens.php
-7
+7
Loading file...
Changes in src/Firebase/Auth.php
-154
+154
Loading file...
Changes in src/Firebase/RemoteConfig/UpdateType.php
-7
+7
Loading file...
Changes in src/Firebase/Auth/SignIn/GuzzleHandler.php
-44
+44
Loading file...
Changes in src/Firebase/Auth/UserMetaData.php
-8
+8
Loading file...
Changes in src/Firebase/RemoteConfig/User.php
-7
+7
Loading file...
Changes in src/Firebase/Http/Middleware.php
-17
+17
Loading file...
Changes in src/Firebase/Auth/ApiClient.php
-28
+28
Loading file...
Changes in src/Firebase/RemoteConfig/UpdateOrigin.php
-5
+5
Loading file...
Changes in src/Firebase/Database/ApiClient.php
-19
+19
Loading file...
Changes in src/Firebase/Messaging/TopicSubscription.php
-6
+6
Loading file...
Changes in src/Firebase/RemoteConfig.php
-16
+16
Loading file...
Changes in src/Firebase/Database/RuleSet.php
-8
+8
Loading file...
Changes in src/Firebase/Messaging.php
-31
+31
Loading file...
Changes in src/Firebase/Messaging/CloudMessage.php
-20
+20
Loading file...
Changes in src/Firebase/DynamicLink/GetStatisticsForDynamicLink.php
-4
+4
Loading file...
Changes in src/Firebase/Auth/SendActionLink.php
-5
+5
Loading file...
Changes in src/Firebase/Messaging/MessageTarget.php
-6
+6
Loading file...
Changes in src/Firebase/Database/Transaction.php
-5
+5
Loading file...
Changes in src/Firebase/Database.php
-5
+5
Loading file...
Changes in src/Firebase/RemoteConfig/Parameter.php
-18
+8
Loading file...
Changes in src/Firebase/Util/Deprecation.php
-1
+1
Loading file...
Changes in src/Firebase/DynamicLink/ShortenLongDynamicLink.php
-4
+4
Loading file...
Changes in src/Firebase/Messaging/FcmOptions.php
-2
+2
Loading file...
Changes in src/Firebase/Storage.php
-2
+2
Loading file...
Changes in src/Firebase/Messaging/Topic.php
-2
+2
Loading file...
Changes in src/Firebase/DynamicLink/CreateDynamicLink.php
-8
+8
Loading file...
Changes in src/Firebase/Factory.php
-35
+35
Loading file...
Changes in src/Firebase/Messaging/Condition.php
-2
+2
Loading file...
Changes in src/Firebase/DynamicLinks.php
-7
+7
Loading file...
Changes in src/Firebase/Exception/RemoteConfigApiExceptionConverter.php
-2
+2
Loading file...
Changes in src/Firebase/Auth/SendActionLink/ApiRequest.php
-1
+1
Loading file...
Changes in src/Firebase/Exception/Database/TransactionFailed.php
-1
+1
Loading file...
Changes in src/Firebase/Exception/DatabaseApiExceptionConverter.php
-1
+1
Loading file...
Changes in src/Firebase/Request/UpdateUser.php
-2
+2
Loading file...
Changes in src/Firebase/Database/Reference.php
-1
+1
Loading file...
New file src/Firebase/RemoteConfig/ParameterGroup.php
New
Loading file...
Changes in src/Firebase/RemoteConfig/Template.php
-3
-1
Loading file...
Files Complexity Coverage
src/Firebase ø -29.00% 66.05%
Project Totals (148 files) 1460 66.05%
Loading