Skip to content

Commit b04b002

Browse files
committed
Improve public API
1 parent 26a3b07 commit b04b002

File tree

8 files changed

+18
-18
lines changed

8 files changed

+18
-18
lines changed

docs/03-value-types.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or provides a class based alternative. The table below summarizes the value type
1717
| String | `string` | `Type::String` | `string` | RFC8941 |
1818
| Boolean | `bool` | `Type::Boolean` | `boolean` | RFC8941 |
1919
| Token | class `Token` | `Type::Token` | `token` | RFC8941 |
20-
| Byte Sequence | class `ByteSequence` | `Type::ByteSequence` | `binary` | RFC8941 |
20+
| Byte Sequence | class `Byte` | `Type::Byte` | `binary` | RFC8941 |
2121
| Date | class `DateTimeImmutable` | `Type::Date` | `date` | RFC9651 |
2222
| DisplayString | class `DisplayString` | `Type::DisplayString` | `displaystring` | RFC9651 |
2323

@@ -70,16 +70,16 @@ Type::fromVariable(42)->isOneOf(Type::Token, Type::Integer); //return true
7070

7171
The RFC defines three (3) specific data types that can not be represented by
7272
PHP default type system, for them, we have defined three classes `Token`,
73-
`ByteSequence` and `DisplayString` to help with their representation.
73+
`Byte` and `DisplayString` to help with their representation.
7474

7575
```php
7676
use Bakame\Http\StructuredFields\Byte;
7777
use Bakame\Http\StructuredFields\DisplayString;
7878
use Bakame\Http\StructuredFields\Token;
7979

8080
Token::fromString(string|Stringable $value): Token
81-
Byte::fromDecoded(string|Stringable $value): ByteSequence;
82-
Byte::fromEncoded(string|Stringable $value): ByteSequence;
81+
Byte::fromDecoded(string|Stringable $value): Byte;
82+
Byte::fromEncoded(string|Stringable $value): Byte;
8383
DisplayString::fromDecoded(string|Stringable $value): DisplayString;
8484
DisplayString::fromEncoded(string|Stringable $value): DisplayString;
8585
```
@@ -109,7 +109,7 @@ $byte->equals(Byte::fromEncoded('SGVsbG8gd29ybGQh')); // will return true
109109
$displayString->equals(DisplayString::fromEncoded('f%c3%bc%c3%bc')); // will return true
110110

111111
$token->type(); // returns Type::Token
112-
$byte->type(); // returns Type::ByteSequence
112+
$byte->type(); // returns Type::Byte
113113
$displayString->type(); // returns Type::DisplayString
114114
```
115115

docs/04-item.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use Bakame\Http\StructuredFields\Byte;
2828
use Bakame\Http\StructuredFields\Item;
2929
use Bakame\Http\StructuredFields\Token;
3030

31-
Item:new(DateTimeInterface|ByteSequence|Token|DisplayString|string|int|array|float|bool $value): self
31+
Item:new(DateTimeInterface|Byte|Token|DisplayString|string|int|array|float|bool $value): self
3232
Item:tryNew(mixed $value): ?self
3333
Item::fromDecodedByteSequence(Stringable|string $value): self;
3434
Item::fromEncodedDisplayString(Stringable|string $value): self;
@@ -51,7 +51,7 @@ To update the `Item` instance value, use the `withValue` method:
5151
```php
5252
use Bakame\Http\StructuredFields\Item;
5353

54-
Item::withValue(DateTimeInterface|ByteSequence|Token|DisplayString|string|int|float|bool $value): static
54+
Item::withValue(DateTimeInterface|Byte|Token|DisplayString|string|int|float|bool $value): static
5555
```
5656

5757
## Item Parameters

docs/05-containers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ use Bakame\Http\StructuredFields\InnerList;
352352
use Bakame\Http\StructuredFields\Item;
353353
use Bakame\Http\StructuredFields\Token;
354354

355-
//@type SfItemInput ByteSequence|Token|DateTimeInterface|string|int|float|bool
355+
//@type SfItemInput Byte|Token|DateTimeInterface|string|int|float|bool
356356

357357
Item::fromAssociative(SfItemInput $value, Parameters|iterable<string, SfItemInput> $parameters): self;
358358
Item::fromPair(array{0:SfItemInput, 1:Parameters|iterable<array{0:string, 1:SfItemInput}>} $pair): self;

docs/06-validation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ $value = $member
133133

134134
> [!NOTE]
135135
> we used `mixed` as parameter type for convenience but the effective parameter type should be
136-
> `ByteSequence|Token|DisplayString|DateTimeImmutable|string|int|float|bool`
136+
> `Byte|Token|DisplayString|DateTimeImmutable|string|int|float|bool`
137137
138138
### Validating the Item parameters.
139139

docs/07-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ which expects a string or a stringable object when adding or updating
1212
HTTP field values.
1313

1414
```php
15-
$container = InnerList::new(ByteSequence::fromDecoded('Hello World'), 42.0, 42);
15+
$container = InnerList::new(Byte::fromDecoded('Hello World'), 42.0, 42);
1616

1717
$container->toHttpValue(); // returns '(:SGVsbG8gV29ybGQ=: 42.0 42)'
1818
echo $container; // returns '(:SGVsbG8gV29ybGQ=: 42.0 42)'

src/Dictionary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ public function indexByName(string $name): ?int
433433
}
434434

435435
/**
436-
* Returns the index associated with the given key or null otherwise.
436+
* Returns the index associated with the given name or null otherwise.
437437
*/
438438
public function nameByIndex(int $index): ?string
439439
{

src/Validation/ParametersValidator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
* @phpstan-import-type SfType from StructuredFieldProvider
1616
*
17-
* @phpstan-type SfParameterKeyRule array{validate?:callable(SfType): (bool|string), required?:bool|string, default?:SfType|null}
17+
* @phpstan-type SfParameterNameRule array{validate?:callable(SfType): (bool|string), required?:bool|string, default?:SfType|null}
1818
* @phpstan-type SfParameterIndexRule array{validate?:callable(SfType, string): (bool|string), required?:bool|string, default?:array{0:string, 1:SfType}|array{}}
1919
*/
2020
final class ParametersValidator
@@ -25,12 +25,12 @@ final class ParametersValidator
2525
/** @var ?callable(Parameters): (string|bool) */
2626
private mixed $criteria;
2727
private int $type;
28-
/** @var array<string, SfParameterKeyRule>|array<int, SfParameterIndexRule> */
28+
/** @var array<string, SfParameterNameRule>|array<int, SfParameterIndexRule> */
2929
private array $filterConstraints;
3030

3131
/**
3232
* @param ?callable(Parameters): (string|bool) $criteria
33-
* @param array<string, SfParameterKeyRule>|array<int, SfParameterIndexRule> $filterConstraints
33+
* @param array<string, SfParameterNameRule>|array<int, SfParameterIndexRule> $filterConstraints
3434
*/
3535
private function __construct(
3636
?callable $criteria = null,
@@ -65,9 +65,9 @@ public function filterByCriteria(?callable $criteria, int $type = self::USE_KEYS
6565
* On success populate the result item property
6666
* On failure populates the result errors property
6767
*
68-
* @param array<string, SfParameterKeyRule> $constraints
68+
* @param array<string, SfParameterNameRule> $constraints
6969
*/
70-
public function filterByKeys(array $constraints): self
70+
public function filterByNames(array $constraints): self
7171
{
7272
return new self($this->criteria, self::USE_KEYS, $constraints);
7373
}
@@ -175,7 +175,7 @@ private function validateByNames(Parameters $parameters): Result /* @phpstan-ign
175175
$violations = new ViolationList();
176176
/**
177177
* @var string $name
178-
* @var SfParameterKeyRule $rule
178+
* @var SfParameterNameRule $rule
179179
*/
180180
foreach ($this->filterConstraints as $name => $rule) {
181181
try {

tests/Validation/ItemValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function it_will_fail_validating_parameters_by_keys(): void
107107
{
108108
$parametersValidator = ParametersValidator::new()
109109
->filterByCriteria(fn (Parameters $parameters) => $parameters->allowedNames(['foo', 'bar']), ParametersValidator::USE_INDICES)
110-
->filterByKeys([
110+
->filterByNames([
111111
'foo' => ['validate' => fn (mixed $value): bool => false],
112112
'bar' => ['validate' => fn (mixed $value): bool => true],
113113
]);

0 commit comments

Comments
 (0)