Skip to content

Commit 2db2c4e

Browse files
committed
Update documentation and improve codebase
1 parent 1e54f8d commit 2db2c4e

File tree

8 files changed

+44
-20
lines changed

8 files changed

+44
-20
lines changed

CHANGELOG.md

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

99
- `Item::fromTimestamp`, `Item::fromDateFormat` to improve item instantiation with dates.
1010
- `ParameterAccess::parameter` to ease parameter members value access.
11+
- **[BC Break]** `ParameterAccess::withoutAllParameters` is renamed `ParameterAccess::withoutAnyParameters`.
1112
- **[BC Break]** `OrderedList` is renamed `OuterList`.
1213
- **[BC Break]** `MemberContainer::remove` methods get added to the interface.
1314
- **[BC Break]** `MemberContainer::keys` method added to the interface.
1415

1516
### Fixed
1617

17-
- Migrate to PHPUnit 10
18+
- Test suite migrated to PHPUnit 10
1819
- Improve Collection immutability with method changes
1920
- **[BC Break]** `ParameterAccess` interface signature updated to use the `Value` interface instead of the `Item` implementation.
2021
- **[BC Break]** `MemberList::remove`, `MemberOrderedMap::remove` and `MemberOrderedMap::keys` methods are moved to their parent interface.
@@ -27,7 +28,8 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
2728

2829
### Removed
2930

30-
- **[BC Break]** `OrderedList` is remove, use `OuterList` instead.
31+
- **[BC Break]** `OrderedList` is removed, use `OuterList` instead.
32+
- **[BC Break]** `ParameterAccess::withoutAllParameters` is removed, use `ParameterAccess::withoutAnyParameters` instead.
3133
- **[BC Break]** remove the `$parameters` argument from all `Item` named constuctore except from `Item::from`.
3234

3335
## [0.7.0] - 2023-02-06

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ have them compliant with the new syntax.
1717
use Bakame\Http\StructuredFields\Item;
1818

1919
$field = Item::from("/terms", ['rel' => 'copyright', 'anchor' => '#foo']);
20-
echo $field->toHttpValue(); // display "/terms";rel="copyright";anchor="#foo"
21-
echo $field->value(); // display "/terms"
22-
echo $field->parameter('rel'); // display "copyright"
20+
echo $field->toHttpValue(); // display "/terms";rel="copyright";anchor="#foo"
21+
echo $field->value(); // display "/terms"
22+
echo $field->parameter('rel'); // display "copyright"
2323
```
2424

2525
## System Requirements
@@ -97,7 +97,7 @@ use Bakame\Http\StructuredFields\Dictionary;
9797

9898
$value = Dictionary::fromAssociative([
9999
'b' => false,
100-
'a' => Item::fromToken('bar', ['baz' => 42]),
100+
'a' => Item::fromToken('bar')->addParameter('baz', 42),
101101
'c' => new DateTimeImmutable('2022-12-23 13:00:23'),
102102
]);
103103

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"require-dev": {
3131
"friendsofphp/php-cs-fixer": "^v3.14.3",
3232
"httpwg/structured-field-tests": "*@dev",
33-
"phpstan/phpstan": "^1.10.3",
33+
"phpstan/phpstan": "^1.10.4",
3434
"phpstan/phpstan-strict-rules": "^1.5.0",
35-
"phpstan/phpstan-phpunit": "^1.3.8",
35+
"phpstan/phpstan-phpunit": "^1.3.10",
3636
"phpstan/phpstan-deprecation-rules": "^1.1.2",
37-
"phpunit/phpunit": "^10.0.13"
37+
"phpunit/phpunit": "^10.0.14"
3838
},
3939
"autoload": {
4040
"psr-4": {

src/InnerList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function withoutParameter(string ...$keys): static
104104
return $this->withParameters($this->parameters()->remove(...$keys));
105105
}
106106

107-
public function withoutAllParameters(): static
107+
public function withoutAnyParameter(): static
108108
{
109109
return $this->withParameters(Parameters::create());
110110
}

src/InnerListTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public function it_can_create_via_parameters_access_methods_a_new_object(): void
206206
$instance3 = $instance1->prependParameter('a', false);
207207
$instance4 = $instance1->withoutParameter('b');
208208
$instance5 = $instance1->withoutParameter('a');
209-
$instance6 = $instance1->withoutAllParameters();
209+
$instance6 = $instance1->withoutAnyParameter();
210210

211211
self::assertSame($instance1, $instance2);
212212
self::assertSame($instance1, $instance7);

src/Item.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ public static function fromTimestamp(int $timestamp): self
102102
*
103103
* @throws SyntaxError if the format is invalid
104104
*/
105-
public static function fromDateFormat(string $format, string $dateString): self
105+
public static function fromDateFormat(string $format, string $datetime): self
106106
{
107-
$value = DateTimeImmutable::createFromFormat($format, $dateString);
107+
$value = DateTimeImmutable::createFromFormat($format, $datetime);
108108
if (false === $value) {
109-
throw new SyntaxError('The date notation `'.$dateString.'` is incompatible with the date format `'.$format.'`.');
109+
throw new SyntaxError('The date notation `'.$datetime.'` is incompatible with the date format `'.$format.'`.');
110110
}
111111

112112
return self::from($value);
@@ -117,7 +117,7 @@ public static function fromDateFormat(string $format, string $dateString): self
117117
*
118118
* @throws SyntaxError if the format is invalid
119119
*/
120-
public static function fromDateString(string $dateString, DateTimeZone|string|null $timezone = null): self
120+
public static function fromDateString(string $datetime, DateTimeZone|string|null $timezone = null): self
121121
{
122122
$timezone ??= date_default_timezone_get();
123123
if (!$timezone instanceof DateTimeZone) {
@@ -128,7 +128,13 @@ public static function fromDateString(string $dateString, DateTimeZone|string|nu
128128
}
129129
}
130130

131-
return self::from(new DateTimeImmutable($dateString, $timezone));
131+
try {
132+
$value = new DateTimeImmutable($datetime, $timezone);
133+
} catch (Throwable $exception) {
134+
throw new SyntaxError('Unable to create a '.DateTimeImmutable::class.' instance with the date notation `'.$datetime.'.`', 0, $exception);
135+
}
136+
137+
return self::from($value);
132138
}
133139

134140
/**
@@ -277,7 +283,7 @@ public function appendParameter(string $key, StructuredField|Token|ByteSequence|
277283
return $this->withParameters($this->parameters()->append($key, $member));
278284
}
279285

280-
public function withoutAllParameters(): static
286+
public function withoutAnyParameter(): static
281287
{
282288
return $this->withParameters(Parameters::create());
283289
}

src/ItemTest.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function it_updates_item(mixed $value, string $expected): void
5656
{
5757
$parameters = Parameters::fromAssociative(['foo' => 'bar']);
5858
if ($value instanceof Value) {
59-
$expected = $value->withoutAllParameters()->toHttpValue();
59+
$expected = $value->withoutAnyParameter()->toHttpValue();
6060
}
6161

6262
self::assertSame(
@@ -173,6 +173,22 @@ public function it_fails_to_instantiate_an_invalid_date_format_string(): void
173173
Item::fromDateFormat(DateTimeInterface::ATOM, '2012-02-03');
174174
}
175175

176+
#[Test]
177+
public function it_fails_to_instantiate_a_date_with_an_invalid_timezone(): void
178+
{
179+
$this->expectException(SyntaxError::class);
180+
181+
Item::fromDateString('+ 5 minutes', 'foobar');
182+
}
183+
184+
#[Test]
185+
public function it_fails_to_instantiate_a_date_with_an_invalid_datetime(): void
186+
{
187+
$this->expectException(SyntaxError::class);
188+
189+
Item::fromDateString('foobar');
190+
}
191+
176192
#[Test]
177193
public function it_instantiates_a_binary(): void
178194
{
@@ -379,7 +395,7 @@ public function it_can_create_via_parameters_access_methods_a_new_object(): void
379395
$instance3 = $instance1->prependParameter('a', false);
380396
$instance4 = $instance1->withoutParameter('b');
381397
$instance5 = $instance1->withoutParameter('a');
382-
$instance6 = $instance1->withoutAllParameters();
398+
$instance6 = $instance1->withoutAnyParameter();
383399

384400
self::assertSame($instance1, $instance2);
385401
self::assertSame($instance1, $instance7);

src/ParameterAccess.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function withoutParameter(string ...$keys): static;
6565
* This method MUST retain the state of the current instance, and return
6666
* an instance that contains the specified parameter change.
6767
*/
68-
public function withoutAllParameters(): static;
68+
public function withoutAnyParameter(): static;
6969

7070
/**
7171
* Returns a new instance with the newly associated parameter instance.

0 commit comments

Comments
 (0)