From e2d9c5219b530e5e2b6cf0d98de0e9113043203e Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 24 Mar 2025 19:13:29 +0100 Subject: [PATCH] [ObjectMapper] CS fixes --- .../Component/ObjectMapper/ObjectMapper.php | 8 ++------ .../ObjectMapper/Tests/ObjectMapperTest.php | 19 +++++++++---------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/Symfony/Component/ObjectMapper/ObjectMapper.php b/src/Symfony/Component/ObjectMapper/ObjectMapper.php index 1f4101cead1fd..6f2a47b621496 100644 --- a/src/Symfony/Component/ObjectMapper/ObjectMapper.php +++ b/src/Symfony/Component/ObjectMapper/ObjectMapper.php @@ -29,14 +29,10 @@ final class ObjectMapper implements ObjectMapperInterface { /** - * A SplObjectStorage that tracks recursive references. + * Tracks recursive references. */ private ?\SplObjectStorage $objectMap = null; - /** - * @param ContainerInterface $transformCallableLocator - * @param ContainerInterface $conditionCallableLocator - */ public function __construct( private readonly ObjectMapperMetadataFactoryInterface $metadataFactory = new ReflectionObjectMapperMetadataFactory(), private readonly ?PropertyAccessorInterface $propertyAccessor = null, @@ -77,7 +73,7 @@ public function map(object $source, object|string|null $target = null): object $mappedTarget = $this->applyTransforms($map, $mappedTarget, $mappedTarget); if (!\is_object($mappedTarget)) { - throw new MappingTransformException(sprintf('Cannot map "%s" to a non-object target of type "%s".', get_debug_type($source), get_debug_type($mappedTarget))); + throw new MappingTransformException(\sprintf('Cannot map "%s" to a non-object target of type "%s".', get_debug_type($source), get_debug_type($mappedTarget))); } } diff --git a/src/Symfony/Component/ObjectMapper/Tests/ObjectMapperTest.php b/src/Symfony/Component/ObjectMapper/Tests/ObjectMapperTest.php index e9ecc2e5dbfb6..afbc350f90316 100644 --- a/src/Symfony/Component/ObjectMapper/Tests/ObjectMapperTest.php +++ b/src/Symfony/Component/ObjectMapper/Tests/ObjectMapperTest.php @@ -100,7 +100,7 @@ public function testHasNothingToMapTo() { $this->expectException(MappingException::class); $this->expectExceptionMessage('Mapping target not found for source "class@anonymous".'); - (new ObjectMapper())->map(new class () {}); + (new ObjectMapper())->map(new class {}); } public function testHasNothingToMapToWithNamedClass() @@ -211,7 +211,7 @@ public function get(string $id): mixed }; } - public function testSourceOnly(): void + public function testSourceOnly() { $a = new \stdClass(); $a->name = 'test'; @@ -220,7 +220,7 @@ public function testSourceOnly(): void $this->assertInstanceOf(SourceOnly::class, $mapped); $this->assertSame('test', $mapped->mappedName); - $a = new class () { + $a = new class { public function __get(string $key): string { return match ($key) { @@ -235,13 +235,12 @@ public function __get(string $key): string $this->assertSame('test', $mapped->mappedName); } - - public function testTransformToWrongValueType(): void + public function testTransformToWrongValueType() { $this->expectException(MappingTransformException::class); $this->expectExceptionMessage('Cannot map "stdClass" to a non-object target of type "string".'); - $u = new \stdClass; + $u = new \stdClass(); $u->foo = 'bar'; $metadata = $this->createStub(ObjectMapperMetadataFactoryInterface::class); @@ -250,16 +249,16 @@ public function testTransformToWrongValueType(): void $mapper->map($u); } - public function testTransformToWrongObject(): void + public function testTransformToWrongObject() { $this->expectException(MappingException::class); - $this->expectExceptionMessage(sprintf('Expected the mapped object to be an instance of "%s" but got "stdClass".', ClassWithoutTarget::class)); + $this->expectExceptionMessage(\sprintf('Expected the mapped object to be an instance of "%s" but got "stdClass".', ClassWithoutTarget::class)); - $u = new \stdClass; + $u = new \stdClass(); $u->foo = 'bar'; $metadata = $this->createStub(ObjectMapperMetadataFactoryInterface::class); - $metadata->method('create')->with($u)->willReturn([new Mapping(target: ClassWithoutTarget::class, transform: fn() => new \stdClass)]); + $metadata->method('create')->with($u)->willReturn([new Mapping(target: ClassWithoutTarget::class, transform: fn () => new \stdClass())]); $mapper = new ObjectMapper($metadata); $mapper->map($u); }