Skip to content

Commit 2b0030e

Browse files
committed
rename create into new named constructor
1 parent b6730b1 commit 2b0030e

File tree

8 files changed

+25
-22
lines changed

8 files changed

+25
-22
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
1616
- `Item::fromString` to improve Item public API;
1717
- `Value` internal class to improve Item public API;
1818
- `Token::toString` to return the string representation of the token.
19+
- `Parameters::new` and `Dictionary::new` to return a new and empty instance
1920

2021
### Fixed
2122

@@ -32,6 +33,8 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this
3233
- **[BC Break]** `Value` interface use a combination of `ValueAccess` **and** `ParameterAccess` instead.
3334
- **[BC Break]** `Token::value` is no longer public use `Token::toString` instead.
3435
- **[BC Break]** `Item::from` is removed use `Item::fromAssociative` instead.
36+
- **[BC Break]** `Parameters::create` is removed use `Parameters::new` instead.
37+
- **[BC Break]** `Dictionary::create` is removed use `Dictionary::new` instead.
3538

3639
## [0.8.0] - 2023-03-12
3740

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,15 @@ echo $value; //;b=?0;a=bar;c=@1671800423
273273
```
274274

275275
If the preference is to use the builder pattern, the same result can be achieved with the following steps.
276-
We start building a `Parameters` or a `Dictionary` instance using the `create` named constructor which
276+
We start building a `Parameters` or a `Dictionary` instance using the `new` named constructor which
277277
returns a new instance with no members.
278278

279279
```php
280280
use Bakame\Http\StructuredFields\Dictionary;
281281
use Bakame\Http\StructuredFields\Item;
282282
use Bakame\Http\StructuredFields\Token;
283283

284-
$value = Dictionary::create()
284+
$value = Dictionary::new()
285285
->add('a', Item::fromToken('bar'))
286286
->prepend('b', Item::false())
287287
->append('c', Item::fromDateString('2022-12-23 13:00:23'))

src/Dictionary.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static function filterMember(mixed $member): object
6161
/**
6262
* Returns a new instance.
6363
*/
64-
public static function create(): self
64+
public static function new(): self
6565
{
6666
return new self();
6767
}

src/DictionaryTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ public function it_can_add_or_remove_members(): void
8484
#[Test]
8585
public function it_returns_the_same_object_if_no_member_is_removed(): void
8686
{
87-
$instance = Dictionary::create();
87+
$instance = Dictionary::new();
8888

8989
self::assertSame($instance, $instance->remove('foo', 'bar', 'baz'));
9090
}
9191

9292
#[Test]
9393
public function it_fails_to_return_an_member_with_invalid_key(): void
9494
{
95-
$instance = Dictionary::create();
95+
$instance = Dictionary::new();
9696

9797
self::assertFalse($instance->has('foobar'));
9898

@@ -104,7 +104,7 @@ public function it_fails_to_return_an_member_with_invalid_key(): void
104104
#[Test]
105105
public function it_fails_to_return_an_member_with_invalid_index(): void
106106
{
107-
$instance = Dictionary::create();
107+
$instance = Dictionary::new();
108108

109109
self::assertFalse($instance->hasPair(1, 2, 3));
110110
self::assertFalse($instance->hasPair());
@@ -125,7 +125,7 @@ public function it_fails_to_add_an_item_with_wrong_key(): void
125125
#[Test]
126126
public function it_can_prepend_a_new_member(): void
127127
{
128-
$instance = Dictionary::create()
128+
$instance = Dictionary::new()
129129
->append('a', Item::fromAssociative(false))
130130
->prepend('b', Item::fromAssociative(true));
131131

@@ -135,7 +135,7 @@ public function it_can_prepend_a_new_member(): void
135135
#[Test]
136136
public function it_can_returns_the_container_member_keys(): void
137137
{
138-
$instance = Dictionary::create();
138+
$instance = Dictionary::new();
139139

140140
self::assertSame([], $instance->keys());
141141

@@ -228,7 +228,7 @@ public function it_can_handle_string_with_comma(): void
228228
#[Test]
229229
public function it_can_delete_a_member_via_array_access(): void
230230
{
231-
$structuredField = Dictionary::create();
231+
$structuredField = Dictionary::new();
232232
$newInstance = $structuredField->add('foo', 'bar');
233233

234234
self::assertTrue($newInstance->hasMembers());
@@ -240,7 +240,7 @@ public function it_fails_to_fetch_an_value_using_an_integer(): void
240240
{
241241
$this->expectException(StructuredFieldError::class);
242242

243-
Dictionary::create()->get(0);
243+
Dictionary::new()->get(0);
244244
}
245245

246246
#[Test]

src/InnerList.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function fromHttpValue(Stringable|string $httpValue): self
6565
*/
6666
public static function from(StructuredField|Token|ByteSequence|DateTimeInterface|Stringable|string|int|float|bool ...$members): self
6767
{
68-
return new self(Parameters::create(), $members);
68+
return new self(Parameters::new(), $members);
6969
}
7070

7171
/**
@@ -153,7 +153,7 @@ public function withoutParameter(string ...$keys): static
153153

154154
public function withoutAnyParameter(): static
155155
{
156-
return $this->withParameters(Parameters::create());
156+
return $this->withParameters(Parameters::new());
157157
}
158158

159159
public function toHttpValue(): string

src/Item.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function fromPair(array $pair): self
9494
*/
9595
private static function fromValue(Value $value): self
9696
{
97-
return new self($value, Parameters::create());
97+
return new self($value, Parameters::new());
9898
}
9999

100100
/**
@@ -287,6 +287,6 @@ public function withoutParameter(string ...$keys): static
287287

288288
public function withoutAnyParameter(): static
289289
{
290-
return $this->withParameters(Parameters::create());
290+
return $this->withParameters(Parameters::new());
291291
}
292292
}

src/Parameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private static function filterMember(mixed $member): object
5959
/**
6060
* Returns a new instance.
6161
*/
62-
public static function create(): self
62+
public static function new(): self
6363
{
6464
return new self();
6565
}

src/ParametersTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function it_fails_to_return_an_member_with_invalid_key(): void
134134
{
135135
$this->expectException(InvalidOffset::class);
136136

137-
$instance = Parameters::create();
137+
$instance = Parameters::new();
138138

139139
self::assertFalse($instance->has('foobar', 'barbaz'));
140140
self::assertFalse($instance->has());
@@ -145,7 +145,7 @@ public function it_fails_to_return_an_member_with_invalid_key(): void
145145
#[Test]
146146
public function it_fails_to_return_an_member_with_invalid_index(): void
147147
{
148-
$instance = Parameters::create();
148+
$instance = Parameters::new();
149149

150150
self::assertFalse($instance->hasPair(3));
151151

@@ -157,7 +157,7 @@ public function it_fails_to_return_an_member_with_invalid_index(): void
157157
#[Test]
158158
public function it_can_prepend_a_new_member(): void
159159
{
160-
$instance = Parameters::create()
160+
$instance = Parameters::new()
161161
->append('a', Item::fromAssociative(false))
162162
->prepend('b', Item::fromAssociative(true));
163163

@@ -168,11 +168,11 @@ public function it_can_prepend_a_new_member(): void
168168
#[Test]
169169
public function it_can_returns_the_container_member_keys(): void
170170
{
171-
$instance = Parameters::create();
171+
$instance = Parameters::new();
172172

173173
self::assertSame([], $instance->keys());
174174

175-
$newInstance = Parameters::create()
175+
$newInstance = Parameters::new()
176176
->append('a', Item::fromAssociative(false))
177177
->prepend('b', Item::fromAssociative(true));
178178

@@ -276,7 +276,7 @@ public function it_successfully_parse_a_parameter_value_with_optional_white_spac
276276
#[Test]
277277
public function it_can_delete_a_member_via_array_access(): void
278278
{
279-
$instance = Parameters::create()->add('foo', 'bar');
279+
$instance = Parameters::new()->add('foo', 'bar');
280280

281281
self::assertTrue($instance->hasMembers());
282282
self::assertFalse($instance->remove('foo')->hasMembers());
@@ -287,7 +287,7 @@ public function it_fails_to_fetch_an_value_using_an_integer(): void
287287
{
288288
$this->expectException(InvalidOffset::class);
289289

290-
Parameters::create()->get(0);
290+
Parameters::new()->get(0);
291291
}
292292

293293
#[Test]

0 commit comments

Comments
 (0)