Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 10 additions & 9 deletions composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -994,17 +994,17 @@
},
{
"name": "gapple/structured-fields",
"version": "v2.3.2",
"version_normalized": "2.3.2.0",
"version": "v2.3.3",
"version_normalized": "2.3.3.0",
"source": {
"type": "git",
"url": "https://github.com/gapple/structured-fields.git",
"reference": "f753bf49ffccc44a1287706c4fab973ddf6e2f5f"
"reference": "4c6936249482d100cc56732aed8c163a76c10dd3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/gapple/structured-fields/zipball/f753bf49ffccc44a1287706c4fab973ddf6e2f5f",
"reference": "f753bf49ffccc44a1287706c4fab973ddf6e2f5f",
"url": "https://api.github.com/repos/gapple/structured-fields/zipball/4c6936249482d100cc56732aed8c163a76c10dd3",
"reference": "4c6936249482d100cc56732aed8c163a76c10dd3",
"shasum": ""
},
"require": {
Expand All @@ -1013,14 +1013,15 @@
"require-dev": {
"httpwg/structured-field-tests": "*@dev",
"paragonie/constant_time_encoding": "^3.0.0",
"phpcompatibility/php-compatibility": "^10@dev",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpunit/phpunit": "^10.5",
"slevomat/coding-standard": "^8.15",
"squizlabs/php_codesniffer": "^3.11"
"squizlabs/php_codesniffer": "^4.0"
},
"time": "2025-04-14T03:43:17+00:00",
"time": "2026-06-12T23:47:46+00:00",
"type": "library",
"extra": {
"branch-alias": {
Expand Down
6 changes: 3 additions & 3 deletions composer/installed.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@
'dev_requirement' => false,
),
'gapple/structured-fields' => array(
'pretty_version' => 'v2.3.2',
'version' => '2.3.2.0',
'reference' => 'f753bf49ffccc44a1287706c4fab973ddf6e2f5f',
'pretty_version' => 'v2.3.3',
'version' => '2.3.3.0',
'reference' => '4c6936249482d100cc56732aed8c163a76c10dd3',
'type' => 'library',
'install_path' => __DIR__ . '/../gapple/structured-fields',
'aliases' => array(),
Expand Down
3 changes: 3 additions & 0 deletions gapple/structured-fields/src/InnerList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace gapple\StructuredFields;

/**
* @method array<TupleInterface|list{mixed,object}> getValue()
*/
class InnerList implements TupleInterface
{
use TupleTrait;
Expand Down
3 changes: 3 additions & 0 deletions gapple/structured-fields/src/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace gapple\StructuredFields;

/**
* @method mixed getValue()
*/
class Item implements TupleInterface
{
use TupleTrait;
Expand Down
8 changes: 7 additions & 1 deletion gapple/structured-fields/src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ private static function parseKey(ParsingInput $input): string
private static function parseBoolean(ParsingInput $input): bool
{
$input->consumeChar('?');
return match ($input->consumeChar()) {
$value = '';
try {
$value = $input->consumeChar();
} catch (\RuntimeException) {
// Consume may throw if value character is missing at end of string. Fall through to default error.
}
return match ($value) {
'0' => false,
'1' => true,
default => throw new ParseException('Invalid boolean at position ' . $input->position()),
Expand Down
22 changes: 13 additions & 9 deletions gapple/structured-fields/src/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ public static function serializeItem(mixed $value, ?object $parameters = null):
}

/**
* @param iterable<TupleInterface|array{mixed, object}> $value
* @param iterable<TupleInterface|list{TupleInterface|list{mixed, object}, object}> $value
*/
public static function serializeList(iterable $value): string
{
if ($value instanceof \Traversable) {
// @todo Checking for Traversable is not required for PHP ^8.2.0.
$value = iterator_to_array($value);
}

$returnValue = array_map(function ($item) {
if ($item instanceof TupleInterface) {
$itemValue = $item->getValue();
$itemParameters = $item->getParameters();
} elseif (is_array($item) && count($item) === 2) {
if (is_array($item) && count($item) === 2) {
$itemValue = $item[0];
$itemParameters = $item[1];
} elseif ($item instanceof TupleInterface) {
$itemValue = $item->getValue();
$itemParameters = $item->getParameters();
} else {
throw new SerializeException("Invalid item in list");
}

if (is_array($itemValue)) {
/** @var array<TupleInterface|list{mixed, object}> $itemValue */
return self::serializeInnerList($itemValue, $itemParameters);
} else {
return self::serializeItem($itemValue, $itemParameters);
Expand All @@ -73,8 +73,6 @@ public static function serializeList(iterable $value): string
* Serialize an object as a dictionary.
*
* Either a Traversable object can be provided, or the public properties of the object will be extracted.
*
* @param Dictionary|object $value
*/
public static function serializeDictionary(object $value): string
{
Expand All @@ -84,6 +82,10 @@ public static function serializeDictionary(object $value): string
$value = get_object_vars($value);
}

/**
* @var string $key
* @var TupleInterface|list{TupleInterface|list{mixed,object}, object} $item
*/
foreach ($value as $key => $item) {
if (!empty($returnValue)) {
$returnValue .= ', ';
Expand All @@ -102,6 +104,7 @@ public static function serializeDictionary(object $value): string
if ($itemValue === true) {
$returnValue .= self::serializeParameters($itemParameters);
} elseif (is_array($itemValue)) {
/** @var array<TupleInterface|list{mixed, object}> $itemValue */
$returnValue .= '=' . self::serializeInnerList($itemValue, $itemParameters);
} else {
$returnValue .= '=' . self::serializeItem($itemValue, $itemParameters);
Expand Down Expand Up @@ -189,7 +192,7 @@ private static function serializeDecimal(float $value): string

// Casting to a string loses a digit on long numbers, but is preserved
// by json_encode (e.g. 111111111111.111).
/** @var string $result */
/** @var non-empty-string $result */
$result = json_encode(round($value, 3, PHP_ROUND_HALF_EVEN));

if (!str_contains($result, '.')) {
Expand Down Expand Up @@ -250,6 +253,7 @@ private static function serializeParameters(object $value): string
$value = get_object_vars($value);
}

/** @var string $key */
foreach ($value as $key => $item) {
$returnValue .= ';' . self::serializeKey($key);

Expand Down