Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: fix(UriVariable): fix string being cast to int #5520

Closed
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
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);
// }
Comment on lines -92 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @PierreRebeilleau, remember me ? ;)

I think this has nothing to do with your PR. So maybe I'm wrong but you might have to revert it.
I actually thought of doing a dedicated PR for this because it affect all the created branch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already did that this needs rebase

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @MarvinCourcier , yes i remember you ! Glad to see you around, ty i'm gonna rebase :)


$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