Skip to content

Commit d018eae

Browse files
committed
Remove MemberContainer::values method
1 parent 76daf79 commit d018eae

12 files changed

+10
-146
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
1616

1717
### Fixed
1818

19-
- **[BC Break]** `Parameters::values` decode `ByteSequence` and `Token` classes.
20-
- **[BC Break]** `Parameters::values` no longer throw on invalid state; value is skipped from returned array.
19+
- None.
2120

2221
### Deprecated
2322

@@ -34,6 +33,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
3433
- **[BC Break]** `::sanitize` method is removed use `Parameters::clear` method instead if needed.
3534
- **[BC Break]** `isEmpty` method is removed use `hasMembers` method instead.
3635
- **[BC Break]** `Parameters::value` use `Item::value` method instead.
36+
- **[BC Break]** `Parameters::values` use `Parameters::getIterator` instead.
3737

3838
## [0.5.0] - 2022-05-13
3939

docs/containers.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ At any given time it is possible with each of these objects to:
2929
- access container members via the `ArrayAccess` interface;
3030
- tell whether the container contains or not members with the `hasMembers` methods from the `Container` interface;
3131
- clear its content using the `clear` method from the `Container` interface;
32-
- unwrap Item value using the `values`, `value` methods from the `Container` interface;
3332

3433
getter methods:
3534

docs/ordered-maps.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ use Bakame\Http\StructuredFields;
6565

6666
$parameters = StructuredFields\Parameters::fromAssociative(['b' => true, 'foo' => 'bar']);
6767
$parameters->keys(); // returns ['b', 'foo']
68-
$parameters->values(); // returns [true, 'bar']
6968
$parameters->get('b'); // returns Item::from(true)
7069
$parameters['b']; // returns Item::from(true)
7170
$parameters['b']->value(); // returns true

src/Dictionary.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Bakame\Http\StructuredFields;
66

77
use Iterator;
8-
use Throwable;
98
use function array_key_exists;
109
use function array_keys;
1110
use function array_map;
@@ -139,44 +138,6 @@ public function has(string|int $offset): bool
139138
return is_string($offset) && array_key_exists($offset, $this->members);
140139
}
141140

142-
/**
143-
* Returns all containers Item values.
144-
*
145-
* @return array<string, array<int, float|int|bool|string>|float|int|bool|string>
146-
*/
147-
public function values(): array
148-
{
149-
$result = [];
150-
foreach ($this->members as $offset => $item) {
151-
$value = $this->value($offset);
152-
if (null !== $value) {
153-
$result[$offset] = $value;
154-
}
155-
}
156-
157-
return $result;
158-
}
159-
160-
/**
161-
* Returns the Item value of a specific key if it exists and is valid otherwise returns null.
162-
*
163-
* @return array<int, float|int|bool|string>|float|int|bool|string|null
164-
*/
165-
private function value(string|int $offset): array|float|int|bool|string|null
166-
{
167-
try {
168-
$member = $this->get($offset);
169-
} catch (Throwable) {
170-
return null;
171-
}
172-
173-
if ($member instanceof Item) {
174-
return $member->value();
175-
}
176-
177-
return $member->values();
178-
}
179-
180141
/**
181142
* Returns the item or the inner-list is attached to the given key otherwise throw.
182143
*

src/DictionaryTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -273,20 +273,14 @@ public function it_can_access_the_item_value(): void
273273
['token', $token],
274274
]);
275275

276-
self::assertSame([
277-
'foobar' => 'foobar',
278-
'zero' => 0,
279-
'false' => false,
280-
'token' => 'token',
281-
], $structuredField->values());
282-
283276
self::assertInstanceOf(Item::class, $structuredField->get('false'));
284277
self::assertFalse($structuredField->get('false')->value());
285278
}
286279

287280
/** @test */
288281
public function it_will_strip_invalid_state_object_via_values_methods(): void
289282
{
283+
$this->expectException(StructuredFieldError::class);
290284
$bar = Item::from(Token::fromString('bar'));
291285
$bar->parameters->set('baz', 42);
292286
$innerList = InnerList::from('foobar');
@@ -296,9 +290,6 @@ public function it_will_strip_invalid_state_object_via_values_methods(): void
296290
->set('c', $innerList);
297291

298292
$structuredField->get('a')->parameters['baz']->parameters->set('error', 'error');
299-
300-
self::assertArrayNotHasKey('a', $structuredField->values());
301-
self::assertEquals(['b' => false, 'c' => [0 => 'foobar']], $structuredField->values());
302-
self::assertSame([0 => 'foobar'], $structuredField->values()['c']);
293+
$structuredField->toHttpValue();
303294
}
304295
}

src/InnerList.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Bakame\Http\StructuredFields;
66

77
use Iterator;
8-
use Throwable;
98
use function array_filter;
109
use function array_map;
1110
use function array_splice;
@@ -114,24 +113,6 @@ private function filterIndex(int $index): int|null
114113
};
115114
}
116115

117-
/**
118-
* Returns all containers Item values.
119-
*
120-
* @return array<int, float|int|bool|string>
121-
*/
122-
public function values(): array
123-
{
124-
$result = [];
125-
foreach ($this->members as $offset => $item) {
126-
try {
127-
$result[$offset] = $this->get($offset)->value();
128-
} catch (Throwable) {
129-
}
130-
}
131-
132-
return $result;
133-
}
134-
135116
public function get(string|int $offset): Item
136117
{
137118
if (!is_int($offset)) {

src/InnerListTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,19 @@ public function it_can_access_the_item_value(): void
208208
$input = ['foobar', 0, false, $token];
209209
$structuredField = InnerList::fromList($input);
210210

211-
self::assertSame(['foobar', 0, false, 'token'], $structuredField->values());
212-
213211
self::assertFalse($structuredField[2]->value());
214212
self::assertSame('token', $structuredField[-1]->value());
215213
}
216214

217215
/** @test */
218216
public function it_will_strip_invalid_state_object_via_values_methods(): void
219217
{
218+
$this->expectException(ForbiddenStateError::class);
220219
$bar = Item::from(Token::fromString('bar'));
221220
$bar->parameters->set('baz', 42);
222221
$structuredField = InnerList::from(false, $bar);
223222
$structuredField[1]->parameters['baz']->parameters->set('error', 'error');
224223

225-
self::assertEquals([false], $structuredField->values());
224+
$structuredField->toHttpValue();
226225
}
227226
}

src/MemberContainer.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,4 @@ public function offsetSet(mixed $offset, mixed $value): void;
6161
* @param TKey $offset
6262
*/
6363
public function offsetUnset(mixed $offset): void;
64-
65-
/**
66-
* @return array<TKey, array<array-key, string|int|float|bool>|string|int|float|bool>
67-
*/
68-
public function values(): array;
6964
}

src/OrderedList.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
namespace Bakame\Http\StructuredFields;
66

77
use Iterator;
8-
use Throwable;
98
use function array_filter;
109
use function array_map;
1110
use function array_splice;
@@ -132,44 +131,6 @@ private function filterIndex(int|string $index): int|null
132131
};
133132
}
134133

135-
/**
136-
* Returns all containers Item values.
137-
*
138-
* @return array<int, array<int, float|int|bool|string>|float|int|bool|string>
139-
*/
140-
public function values(): array
141-
{
142-
$result = [];
143-
foreach ($this->members as $offset => $item) {
144-
$value = $this->value($offset);
145-
if (null !== $value) {
146-
$result[$offset] = $value;
147-
}
148-
}
149-
150-
return $result;
151-
}
152-
153-
/**
154-
* Returns the Item value of a specific key if it exists and is valid otherwise returns null.
155-
*
156-
* @return array<int, float|int|bool|string>|float|int|bool|string|null
157-
*/
158-
private function value(string|int $offset): array|float|int|bool|string|null
159-
{
160-
try {
161-
$member = $this->get($offset);
162-
} catch (Throwable) {
163-
return null;
164-
}
165-
166-
if ($member instanceof Item) {
167-
return $member->value();
168-
}
169-
170-
return $member->values();
171-
}
172-
173134
public function get(string|int $offset): Item|InnerList
174135
{
175136
if (!is_int($offset)) {

src/OrderedListTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,21 @@ public function it_can_access_the_item_value(): void
188188
$input = ['foobar', 0, false, $token, $innerList];
189189
$structuredField = OrderedList::fromList($input);
190190

191-
self::assertSame(['foobar', 0, false, 'token', [0 => 'test']], $structuredField->values());
192191
self::assertInstanceOf(Item::class, $structuredField[2]);
193192
self::assertFalse($structuredField[2]->value());
194193

195194
self::assertInstanceOf(InnerList::class, $structuredField[-1]);
196-
self::assertSame([0 => 'test'], $structuredField[-1]->values());
197195
}
198196

199197
/** @test */
200198
public function it_will_strip_invalid_state_object_via_values_methods(): void
201199
{
200+
$this->expectException(ForbiddenStateError::class);
202201
$bar = Item::from(Token::fromString('bar'));
203202
$bar->parameters->set('baz', 42);
204203
$structuredField = OrderedList::from(false, $bar);
205204
$structuredField[1]->parameters['baz']->parameters->set('error', 'error');
206205

207-
self::assertEquals([false], $structuredField->values());
206+
$structuredField->toHttpValue();
208207
}
209208
}

0 commit comments

Comments
 (0)