@@ -17,6 +17,9 @@
Loading
17 17
    /** @var Parameter[] */
18 18
    private $parameters = [];
19 19
20 +
    /** @var ParameterGroup[] */
21 +
    private $parameterGroups = [];
22 +
20 23
    /** @var Condition[] */
21 24
    private $conditions = [];
22 25
@@ -64,6 +67,25 @@
Loading
64 67
            $template->parameters[(string) $name] = Parameter::fromArray([(string) $name => $parameterData]);
65 68
        }
66 69
70 +
        foreach ((array) ($data['parameterGroups'] ?? []) as $name => $parameterGroupData) {
71 +
            $group = ParameterGroup::named((string) $name)
72 +
                ->withDescription((string) ($parameterGroupData['description'] ?? ''));
73 +
74 +
            foreach ($parameterGroupData['parameters'] ?? [] as $parameterName => $parameterData) {
75 +
                $parameter = Parameter::named($parameterName)
76 +
                    ->withDescription((string) ($parameterData['description'] ?? ''))
77 +
                    ->withDefaultValue(DefaultValue::fromArray($parameterData['defaultValue'] ?? []));
78 +
79 +
                foreach ((array) ($parameterData['conditionalValues'] ?? []) as $key => $conditionalValueData) {
80 +
                    $parameter = $parameter->withConditionalValue(new ConditionalValue($key, $conditionalValueData['value']));
81 +
                }
82 +
83 +
                $group = $group->withParameter($parameter);
84 +
            }
85 +
86 +
            $template->parameterGroups[$group->name()] = $group;
87 +
        }
88 +
67 89
        if (\is_array($data['version'] ?? null)) {
68 90
            try {
69 91
                $template->version = Version::fromArray($data['version']);
@@ -91,6 +113,14 @@
Loading
91 113
        return $this->parameters;
92 114
    }
93 115
116 +
    /**
117 +
     * @return ParameterGroup[]
118 +
     */
119 +
    public function parameterGroups(): array
120 +
    {
121 +
        return $this->parameterGroups;
122 +
    }
123 +
94 124
    public function version(): ?Version
95 125
    {
96 126
        return $this->version;
@@ -106,6 +136,14 @@
Loading
106 136
        return $template;
107 137
    }
108 138
139 +
    public function withParameterGroup(ParameterGroup $parameterGroup): Template
140 +
    {
141 +
        $template = clone $this;
142 +
        $template->parameterGroups[$parameterGroup->name()] = $parameterGroup;
143 +
144 +
        return $template;
145 +
    }
146 +
109 147
    public function withCondition(Condition $condition): Template
110 148
    {
111 149
        $template = clone $this;
@@ -118,7 +156,7 @@
Loading
118 156
    {
119 157
        foreach ($parameter->conditionalValues() as $conditionalValue) {
120 158
            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.';
159 +
                $message = 'The conditional value of the parameter named "%s" refers to a condition "%s" which does not exist.';
122 160
123 161
                throw new InvalidArgumentException(\sprintf($message, $parameter->name(), $conditionalValue->conditionName()));
124 162
            }
@@ -130,11 +168,10 @@
Loading
130 168
     */
131 169
    public function jsonSerialize(): array
132 170
    {
133 -
        $result = [
171 +
        return [
134 172
            'conditions' => \array_values($this->conditions),
135 173
            'parameters' => $this->parameters,
174 +
            'parameterGroups' => $this->parameterGroups,
136 175
        ];
137 -
138 -
        return \array_filter($result);
139 176
    }
140 177
}

@@ -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 +
}
Files Complexity Coverage
src/Firebase 1,455 64.57%
Project Totals (148 files) 1455 64.57%
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