Skip to content

Commit 2008e26

Browse files
committed
BC break on Item::value return type
1 parent 5e8df3c commit 2008e26

File tree

5 files changed

+31
-15
lines changed

5 files changed

+31
-15
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# Changelog
22

33
All Notable changes to `bakame/http-strucured-fields` will be documented in this file
4+
5+
## [Next] - TBD
6+
7+
### Added
8+
9+
- None
10+
11+
### Fixed
12+
13+
- **[BC Break]** `Item::value` method returns the Item (returns value can be `float|int|string|bool|ByteSequence|Token`).
14+
15+
### Deprecated
16+
17+
- None
18+
19+
### Removed
20+
21+
- None
422

523
## [0.6.0] - 2022-11-12
624

docs/item.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ $item = StructuredFields\Item::fromPair([
9898
$item->value(); // returns "hello world"
9999
$item->isString(); // returns true
100100
$item->parameters()["a"]->isByteSequence(); // returns true
101-
$item->parameters()["a"]->value(); // returns the decoded value 'Hello World'
102-
echo $item->toHttpValue(); // returns "hello world";a=:SGVsbG8gV29ybGQ=:
101+
$item->parameters()["a"]->value(); // returns StructuredFields\ByteSequence::fromDecoded('Hello World');
102+
echo $item->toHttpValue(); // returns "hello world";a=:SGVsbG8gV29ybGQ=:
103103
```
104104

105105
`Item::fromPair` is an alternative to the `Item::from` named constructor, it expects
@@ -117,9 +117,9 @@ Once instantiated, accessing `Item` properties is done via:
117117
```php
118118
use Bakame\Http\StructuredFields;
119119

120-
$item = StructuredFields\Item::from(StructuredFields\ByteSequence::fromEncoded("SGVsbG8gV29ybGQ=")]);
120+
$item = StructuredFields\Item::from(StructuredFields\ByteSequence::fromEncoded("SGVsbG8gV29ybGQ="));
121121
$item->isByteSequence(); // returns true
122-
echo $item->value(); // returns the decoded value 'Hello World'
122+
echo $item->value(); // returns StructuredFields\ByteSequence::fromEncoded("SGVsbG8gV29ybGQ=");
123123
```
124124

125125
**Of note: to instantiate a decimal number type a float MUST be used as the first argument of `Item::from`.**

src/InnerListTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function it_successfully_parse_a_http_field(): void
130130
self::assertSame('hello)world', $instance->get(0)->value());
131131
self::assertSame(42, $instance->get(1)->value());
132132
self::assertSame(42.0, $instance->get(2)->value());
133-
self::assertSame('doe', $instance->get(2)->parameters()['john']->value());
133+
self::assertEquals(Token::fromString('doe'), $instance->get(2)->parameters()['john']->value());
134134
}
135135

136136
/** @test */
@@ -194,7 +194,7 @@ public function it_can_access_the_item_value(): void
194194
$structuredField = InnerList::fromList($input);
195195

196196
self::assertFalse($structuredField[2]->value());
197-
self::assertSame('token', $structuredField[-1]->value());
197+
self::assertEquals($token, $structuredField[-1]->value());
198198
}
199199

200200
/** @test */

src/Item.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,9 @@ private function serializeDecimal(float $value): string
290290
/**
291291
* Returns the underlying value decoded.
292292
*/
293-
public function value(): string|int|float|bool
293+
public function value(): Token|ByteSequence|int|float|string|bool
294294
{
295-
return match (true) {
296-
$this->value instanceof Token => $this->value->value,
297-
$this->value instanceof ByteSequence => $this->value->decoded(),
298-
default => $this->value,
299-
};
295+
return $this->value;
300296
}
301297

302298
public function withValue(Token|ByteSequence|int|float|string|bool $value): self

src/ItemTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ public function it_instantiates_a_token(): void
8181
/** @test */
8282
public function it_instantiates_a_binary(): void
8383
{
84-
self::assertSame('foobar', Item::from(ByteSequence::fromDecoded('foobar'))->value());
85-
self::assertSame('foobar', Item::fromDecodedByteSequence('foobar')->value());
86-
self::assertSame('foobar', Item::fromEncodedByteSequence('Zm9vYmFy')->value());
84+
$byteSequence = ByteSequence::fromDecoded('foobar');
85+
86+
self::assertEquals($byteSequence, Item::from(ByteSequence::fromDecoded('foobar'))->value());
87+
self::assertEquals($byteSequence, Item::fromDecodedByteSequence('foobar')->value());
88+
self::assertEquals($byteSequence, Item::fromEncodedByteSequence('Zm9vYmFy')->value());
8789
}
8890

8991
/** @test */

0 commit comments

Comments
 (0)