Skip to content

Commit f2c995a

Browse files
committed
Improve interface name
1 parent 3aeca56 commit f2c995a

18 files changed

+105
-103
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
66

77
### Added
88

9-
- Introduce the`StructuredFieldContainer` interface.
10-
- `OrderedList`, `InnerList` now implements the `StructuredFieldList` interface.
11-
- `Parameters` and `Dictionnary` now implements the PHP `StructuredFieldOrderedMap` interface.
9+
- Introduce the`MemberContainer` interface.
10+
- `OrderedList`, `InnerList` now implements the `MemberList` interface.
11+
- `Parameters` and `Dictionnary` now implements the PHP `MemberOrderedMap` interface.
1212
- `Token::value` is a readonly property.
1313
- `Item::value` method returns the decoded value of an Item (returns value can be `float|int|string|bool`).
1414
- `Item::fromToken`, `Item::fromDecodedByteSequence` , `Item::fromEncodedByteSequence` to ease specific string initiation

docs/basic-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ an HTTP field value can be:
77
- a [Dictionary](ordered-maps.md);
88
- a [List](lists.md);
99

10-
For each of these top-level types, the package provides a dedicated value object to parse the textual
10+
For each of these top-level types, the package provides a dedicated object to parse the textual
1111
representation of the field and to serialize the value object back to the textual representation.
1212

1313
- Parsing is done via a common named constructor `fromHttpValue` which expects the Header or Trailer string value.

docs/containers.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use Bakame\Http\StructuredFields;
55

66
$parameters = StructuredFields\Parameters::fromAssociative(['a' => 1, 'b' => 2, 'c' => "hello world"]);
77
count($parameters); // returns 3
8-
$parameters->isEmpty(); // returns false
8+
$parameters->hasMembers(); // returns true
99
$parameters->toHttpValue(); // returns ';a=1;b=2;c="hello world"'
10-
$parameters->clear()->isEmpty(); // returns true
10+
$parameters->clear()->hasNoMembers(); // returns true
1111
```
1212

1313
The package exposes [ordered maps](ordered-maps.md)
@@ -20,22 +20,22 @@ and [lists](lists.md)
2020
- OrderedList,
2121
- and InnerList
2222

23-
with different requirements. At any given time it is possible with each of these objects to:
23+
with different requirements.
24+
25+
At any given time it is possible with each of these objects to:
2426

2527
- iterate over its members using the `IteratorAggregate` interface;
2628
- know the number of members it contains via the `Countable` interface;
27-
- Access container members via the `ArrayAccess` interface;
28-
- tell whether the container is empty or not using the `isEmpty` and/or `hasMembers` methods from the `StrucutedFieldContainer` interface;
29-
- clear its content using the `clear` method from the `StrucutedFieldContainer` interface;
30-
- unwrap Item value using the `values`, `value` methods from the `StrucutedFieldContainer` interface;
29+
- access container members via the `ArrayAccess` interface;
30+
- tell whether the container contains or not members with the `hasNoMembers` and/or `hasMembers` methods from the `MemberContainer` interface;
31+
- clear its content using the `clear` method from the `MemberContainer` interface;
32+
- unwrap Item value using the `values`, `value` methods from the `MemberContainer` interface;
3133

3234
getter methods:
3335

3436
- `get` to access an element at a given index (negative indexes are supported)
3537
- `has` tell whether an element is attached to the container using its `index`;
3638

37-
38-
3939
**Of note:**
4040

4141
- All setter methods are chainable

docs/item.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ echo $token->value; // displays 'bar'
3030
```
3131

3232
The Token data type is a special string as defined in the RFC. To distinguish it from a normal string,
33-
the `Bakame\Http\StructuredFields\Token` class is used.
33+
the `Bakame\Http\StructuredFields\Token` class can be used.
3434

3535
To instantiate the class you are required to use the `Token::fromString` named constructor.
3636
The class also exposes its value via the public readonly property `value` to enable its textual representation.
@@ -52,14 +52,15 @@ To distinguish it from a normal string, the `Bakame\Http\StructuredFields\ByteSe
5252

5353
To instantiate the class you are required to use the `ByteSequence::fromDecoded` or `ByteSequence::fromEncoded`
5454
named constructors. The class also exposes the complementary public methods `ByteSequence::decoded`,
55-
`ByteSequence::encoded` to enable its textual representation.
55+
`ByteSequence::encoded` to enable the correct textual representation.
5656

5757
## Usages
5858

59-
Items can be associated with an ordered maps of key-value pairs also known as parameters, where the
59+
Items can be associated with parameters that are an ordered maps of key-value pairs where the
6060
keys are strings and the value are bare items. Their public API is covered in the [ordered maps section](ordered-maps.md].
6161

6262
**An item without any parameter associated to it is said to be a bare item.**
63+
**Exception will be thrown when trying to access or serialize a parameter object containing non-bare items.**
6364

6465
```php
6566
use Bakame\Http\StructuredFields;
@@ -77,6 +78,15 @@ Instantiation via type recognition is done using the `Item::from` named construc
7778
- The second argument, which is optional, MUST be an iterable construct
7879
where its index represents the parameter key and its value an item or an item type value;
7980

81+
It is possible to use
82+
83+
- `Item::fromToken` internally use `Token::fromString` to
84+
- `Item::fromEncodedByteSequence` internally use `ByteSequence::fromEncoded`
85+
- `Item::fromDecodedByteSequence` internally use `ByteSequence::fromDecoded`
86+
87+
Those listed named constructores expect a string or a stringable object as its first argument and the
88+
same argument definition as in `Item::from` for parameters argument.
89+
8090
```php
8191
use Bakame\Http\StructuredFields;
8292

@@ -93,28 +103,17 @@ $item->parameters->value("a"); // returns the decoded value 'Hello World'
93103
echo $item->toHttpValue(); // returns "hello world";a=:SGVsbG8gV29ybGQ=:
94104
```
95105

96-
It is possible to use
97-
98-
- `Item::fromToken` internally use `Token::fromString` to
99-
- `Item::fromEncodedByteSequence` internally use `ByteSequence::fromEncoded`
100-
- `Item::fromDecodedByteSequence` internally use `ByteSequence::fromDecoded`
101-
102-
Thos listed named constructores expect a string as its first argument and the
103-
same argument definition as in `Item::from` for parameters argument.
104-
105106
`Item::fromPair` is an alternative to the `Item::from` named constructor, it expects
106107
a tuple composed by an array as a list where:
107108

108109
- The first member on index `0` represents one of the six (6) item type value;
109110
- The second optional member, on index `1`, **MUST** be an iterable construct containing
110111
tuples of key-value pairs;
111112

112-
Once instantiated, accessing `Item` properties is done via two (2) readonly properties:
113-
114-
- `Item::value` which returns the instance underlying value
115-
- `Item::parameters` which returns the parameters associated to the `Item` as a distinct `Parameters` object
113+
Once instantiated, accessing `Item` properties is done via:
116114

117-
And on method called `Item::decodedValue()` which returns the underlying value fully decoded.
115+
- the method `Item::value` which returns the instance underlying value fully decoded;
116+
- the readonly property `Item::parameters` which returns the parameters associated to the `Item` as a distinct `Parameters` object
118117

119118
```php
120119
use Bakame\Http\StructuredFields;

docs/lists.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ setter methods
2727
- `replace` to replace an element at a given position in the list;
2828
- `remove` to remove elements based on their position;
2929

30-
Additionally, both classes implements PHP `ArrayAccess` interface as syntactic sugar methods
31-
around the `get`, `has`, `push`, `remove` and `replace` methods.
30+
In addition to `StructuredField` specific interfaces, both classes implements:
31+
32+
- PHP `Countable` interface.
33+
- PHP `IteratorAggregate` interface.
34+
- PHP `ArrayAccess` interface.
3235

3336
```php
3437
use Bakame\Http\StructuredFields;
@@ -68,6 +71,7 @@ your logic**
6871
```php
6972
use Bakame\Http\StructuredFields;
7073

71-
$innerList = StructuredFields\OrderedList::fromList([42, 42.0, "42"], ["a" => true]);
74+
$innerList = StructuredFields\OrderedList::fromList([42, 42.0]);
7275
$innerList[2] = StructuredFields\Token::fromString('forty-two'); // will throw
76+
echo $innerList->toHttpValue(), PHP_EOL;
7377
```

docs/ordered-maps.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ echo $dictionary
5454
->toHttpValue(); // returns "a=?0, z=42.0"
5555
```
5656

57-
## Parameters specific methods
57+
In addition to `StructuredField` specific interfaces, both classes implements:
5858

59-
The `Parameters` instance exposes the following additional methods:
60-
61-
- `Parameters::values` to list all existing Bare Item values as an array list;
62-
- `Parameters::value` to return the value of the Bare Item associated to the `$key` or `null` if the key is unknown or invalid;
59+
- PHP `Countable` interface.
60+
- PHP `IteratorAggregate` interface.
61+
- PHP `ArrayAccess` interface.
6362

6463
```php
6564
use Bakame\Http\StructuredFields;
@@ -69,7 +68,7 @@ $parameters->keys(); // returns ['b', 'foo']
6968
$parameters->values(); // returns [true, 'bar']
7069
$parameters->value('b'); // returns true
7170
$parameters->get('b'); // returns Item::from(true)
72-
$parameters['b']; // returns Item::from(true)
71+
$parameters['b']; // returns Item::from(true)
7372
iterator_to_array($parameters->toPairs(), true); // returns [['b', Item::from(true)], ['foo', Item::from('bar')]]
7473
iterator_to_array($parameters, true); // returns ['b' => Item::from(true), 'foo' => Item::from('bar')]
7574
$parameters->mergeAssociative(

src/Dictionary.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
use function is_array;
1717

1818
/**
19-
* @implements StructuredFieldOrderedMap<string, Item|InnerList<int, Item>>
19+
* @implements MemberOrderedMap<string, Item|InnerList<int, Item>>
2020
*/
21-
final class Dictionary implements StructuredFieldOrderedMap
21+
final class Dictionary implements MemberOrderedMap
2222
{
2323
/** @var array<string, Item|InnerList<int, Item>> */
2424
private array $members = [];
@@ -53,11 +53,11 @@ public static function fromAssociative(iterable $members = []): self
5353
* the first member represents the instance entry key
5454
* the second member represents the instance entry value
5555
*
56-
* @param StructuredFieldOrderedMap<string, Item|InnerList<int, Item>>|iterable<array{0:string, 1:InnerList<int, Item>|Item|ByteSequence|Token|bool|int|float|string}> $pairs
56+
* @param MemberOrderedMap<string, Item|InnerList<int, Item>>|iterable<array{0:string, 1:InnerList<int, Item>|Item|ByteSequence|Token|bool|int|float|string}> $pairs
5757
*/
58-
public static function fromPairs(StructuredFieldOrderedMap|iterable $pairs = []): self
58+
public static function fromPairs(MemberOrderedMap|iterable $pairs = []): self
5959
{
60-
if ($pairs instanceof StructuredFieldOrderedMap) {
60+
if ($pairs instanceof MemberOrderedMap) {
6161
$pairs = $pairs->toPairs();
6262
}
6363

@@ -97,14 +97,14 @@ public function count(): int
9797
return count($this->members);
9898
}
9999

100-
public function isEmpty(): bool
100+
public function hasNoMembers(): bool
101101
{
102102
return [] === $this->members;
103103
}
104104

105105
public function hasMembers(): bool
106106
{
107-
return !$this->isEmpty();
107+
return !$this->hasNoMembers();
108108
}
109109

110110
/**
@@ -355,9 +355,9 @@ public function mergeAssociative(iterable ...$others): self
355355
/**
356356
* Merges multiple instances using iterable pairs.
357357
*
358-
* @param StructuredFieldOrderedMap<string, Item|InnerList<int, Item>>|iterable<array{0:string, 1:InnerList<int, Item>|Item|ByteSequence|Token|bool|int|float|string}> ...$others
358+
* @param MemberOrderedMap<string, Item|InnerList<int, Item>>|iterable<array{0:string, 1:InnerList<int, Item>|Item|ByteSequence|Token|bool|int|float|string}> ...$others
359359
*/
360-
public function mergePairs(StructuredFieldOrderedMap|iterable ...$others): self
360+
public function mergePairs(MemberOrderedMap|iterable ...$others): self
361361
{
362362
foreach ($others as $other) {
363363
$this->members = [...$this->members, ...self::fromPairs($other)->members];

src/DictionaryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function it_can_be_instantiated_with_an_collection_of_item_or_inner_list(
3131

3232
self::assertEquals($arrayParams, iterator_to_array($instance));
3333
$instance->clear();
34-
self::assertTrue($instance->isEmpty());
34+
self::assertTrue($instance->hasNoMembers());
3535
self::assertFalse($instance->hasMembers());
3636
}
3737

@@ -63,7 +63,7 @@ public function it_can_add_or_remove_members(): void
6363
$instance = Dictionary::fromAssociative($arrayParams);
6464

6565
self::assertCount(2, $instance);
66-
self::assertFalse($instance->isEmpty());
66+
self::assertFalse($instance->hasNoMembers());
6767
$instance->delete('boolean');
6868

6969
self::assertCount(1, $instance);
@@ -82,7 +82,7 @@ public function it_can_add_or_remove_members(): void
8282

8383
$instance->delete('foobar', 'string');
8484
self::assertCount(0, $instance);
85-
self::assertTrue($instance->isEmpty());
85+
self::assertTrue($instance->hasNoMembers());
8686
}
8787

8888
/** @test */

src/InnerList.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use function count;
1515

1616
/**
17-
* @implements StructuredFieldList<int, Item>
17+
* @implements MemberList<int, Item>
1818
*/
19-
final class InnerList implements StructuredFieldList
19+
final class InnerList implements MemberList
2020
{
2121
/** @var array<int, Item> */
2222
private array $members;
@@ -85,14 +85,14 @@ public function count(): int
8585
return count($this->members);
8686
}
8787

88-
public function isEmpty(): bool
88+
public function hasNoMembers(): bool
8989
{
9090
return [] === $this->members;
9191
}
9292

9393
public function hasMembers(): bool
9494
{
95-
return !$this->isEmpty();
95+
return !$this->hasNoMembers();
9696
}
9797

9898
/**

src/InnerListTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ public function it_can_be_instantiated_with_an_collection_of_item(): void
1919
$booleanItem = Item::from(true);
2020
$arrayParams = [$stringItem, $booleanItem];
2121
$instance = InnerList::fromList($arrayParams, Parameters::fromAssociative(['test' => Item::from(42)]));
22-
self::assertFalse($instance->parameters->isEmpty());
22+
self::assertFalse($instance->parameters->hasNoMembers());
2323

2424
self::assertSame($stringItem, $instance->get(0));
25-
self::assertFalse($instance->isEmpty());
25+
self::assertFalse($instance->hasNoMembers());
2626

2727
self::assertEquals($arrayParams, iterator_to_array($instance));
2828
$instance->clear();
29-
self::assertTrue($instance->isEmpty());
29+
self::assertTrue($instance->hasNoMembers());
3030
self::assertFalse($instance->hasMembers());
3131
}
3232

@@ -40,7 +40,7 @@ public function it_can_add_or_remove_members(): void
4040

4141
self::assertCount(2, $instance);
4242
self::assertTrue($instance->has(1));
43-
self::assertTrue($instance->parameters->isEmpty());
43+
self::assertTrue($instance->parameters->hasNoMembers());
4444
self::assertFalse($instance->parameters->hasMembers());
4545

4646
$instance->remove(1);
@@ -57,7 +57,7 @@ public function it_can_add_or_remove_members(): void
5757

5858
$instance->remove(0, 1);
5959
self::assertCount(0, $instance);
60-
self::assertTrue($instance->isEmpty());
60+
self::assertTrue($instance->hasNoMembers());
6161
self::assertFalse($instance->hasMembers());
6262
}
6363

@@ -71,7 +71,7 @@ public function it_can_unshift_insert_and_replace(): void
7171
$container->replace(0, ByteSequence::fromDecoded('Hello World'));
7272

7373
self::assertCount(3, $container);
74-
self::assertFalse($container->isEmpty());
74+
self::assertFalse($container->hasNoMembers());
7575
self::assertSame('(:SGVsbG8gV29ybGQ=: 42.0 42)', $container->toHttpValue());
7676
}
7777

0 commit comments

Comments
 (0)