Skip to content

Commit

Permalink
Allow nullable string properties.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crell committed Aug 20, 2023
1 parent d24f6b1 commit 030ba36
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Formatter/ArrayBasedFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function serializeFloat(mixed $runningValue, Field $field, float $next):
/**
* @param array<string, mixed> $runningValue
* @param Field $field
* @param string $next
* @param string|null $next
* @return array<string, mixed>
*/
public function serializeString(mixed $runningValue, Field $field, string $next): array
public function serializeString(mixed $runningValue, Field $field, ?string $next): array
{
$runningValue[$field->serializedName] = $next;
return $runningValue;
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/CsvStreamFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function format(): string
/**
* @param FormatterStream $runningValue
*/
public function serializeString(mixed $runningValue, Field $field, string $next): mixed
public function serializeString(mixed $runningValue, Field $field, ?string $next): mixed
{
$next = str_replace($this->enclosure, $this->escape . $this->enclosure, $next);
$runningValue->write($this->enclosure . $next . $this->enclosure);
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function serializeInt(mixed $runningValue, Field $field, int $next): mixe

public function serializeFloat(mixed $runningValue, Field $field, float $next): mixed;

public function serializeString(mixed $runningValue, Field $field, string $next): mixed;
public function serializeString(mixed $runningValue, Field $field, ?string $next): mixed;

public function serializeBool(mixed $runningValue, Field $field, bool $next): mixed;

Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/StreamFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function serializeFloat(mixed $runningValue, Field $field, float $next):
return $runningValue;
}

public function serializeString(mixed $runningValue, Field $field, string $next): mixed
public function serializeString(mixed $runningValue, Field $field, ?string $next): mixed
{
$runningValue->printf('"%s"', $next);
return $runningValue;
Expand Down
2 changes: 1 addition & 1 deletion tests/ArrayBasedFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected function empty_values_validate(mixed $serialized): void
self::assertEquals('boop', $toTest['withDefault']);
self::assertArrayNotHasKey('nullableUninitialized', $toTest);
self::assertArrayNotHasKey('uninitialized', $toTest);
self::assertArrayNotHasKey('roNullable', $toTest);
self::assertNull($toTest['roNullable']);
}

public function exclude_values_validate(mixed $serialized): void
Expand Down
2 changes: 1 addition & 1 deletion tests/JsonFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function point_validate(mixed $serialized): void
protected function visibility_validate(mixed $serialized): void
{
parent::visibility_validate($serialized);
self::assertEquals('{"public":1,"protected":2,"private":3,"visibility":{"public":4,"protected":5,"private":6}}', $serialized);
self::assertEquals('{"public":1,"protected":2,"private":3,"visibility":{"public":4,"protected":5,"private":6,"visibility":null}}', $serialized);
}

protected function optional_point_validate(mixed $serialized): void
Expand Down

0 comments on commit 030ba36

Please sign in to comment.