Skip to content

Commit

Permalink
fix(metadata): fix string being cast to int
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRebeilleau committed Apr 3, 2023
1 parent 6157332 commit 9177449
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

final class IntegerUriVariableTransformer implements UriVariableTransformerInterface
{
public function transform(mixed $value, array $types, array $context = []): int
public function transform(mixed $value, array $types, array $context = []): int|string
{
return (int) $value;
return is_numeric($value) ? (int) $value : $value;
}

public function supportsTransformation(mixed $value, array $types, array $context = []): bool
Expand Down
6 changes: 3 additions & 3 deletions src/Metadata/Resource/ResourceMetadataCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public function getOperation(?string $operationName = null, bool $forceCollectio
}

// Idea:
// if ($metadata) {
// return (new class extends HttpOperation {})->withResource($metadata);
// }
// if ($metadata) {
// return (new class extends HttpOperation {})->withResource($metadata);
// }

$this->handleNotFound($operationName, $metadata);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public function testTransform(): void
$this->assertSame(2, (new IntegerUriVariableTransformer())->transform('2', ['int']));
}

public function testCastString(): void
{
$this->assertSame('7foo', (new IntegerUriVariableTransformer())->transform('7foo', ['int']));
}

public function testSupportsTransformation(): void
{
$normalizer = new IntegerUriVariableTransformer();
Expand Down

0 comments on commit 9177449

Please sign in to comment.