8000 Apply suggestions from code review · symfony/symfony@63322b3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 63322b3

Browse files
soyukadunglas
andauthored
Apply suggestions from code review
Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
1 parent 139a158 commit 63322b3

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/Symfony/Component/AutoMapper/Attributes/MapIf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
final class MapIf
1515
{
1616
/**
17-
* @param callable $if
17+
* @param string|callable(mixed $value, object $object): bool $if
1818
*/
19-
public function __construct(public mixed $if)
19+
public function __construct(public readonly string|callable $if)
2020
{
2121
}
2222
}

src/Symfony/Component/AutoMapper/Attributes/MapTo.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
use Attribute;
66

77
/**
8-
* Configure a class or a property to map to.
8+
* Configures a class or a property to map to.
99
*
1010
* @experimental
1111
* @author Antoine Bluchet <soyuka@gmail.com>
1212
*/
1313
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY)]
1414
final class MapTo
1515
{
16-
public function __construct(public string $to)
16+
public function __construct(public readonly string $to)
1717
{
1818
}
1919
}

src/Symfony/Component/AutoMapper/Attributes/MapWith.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Attribute;
66

77
/**
8-
* Transform the mapped value with a funtion.
8+
* Transforms the mapped value with a function.
99
*
1010
* @experimental
1111
* @author Antoine Bluchet <soyuka@gmail.com>
@@ -14,9 +14,9 @@
1414
final class MapWith
1515
{
1616
/**
17-
* @param callable $with
17+
* @param string|callable(mixed $value, object $object): bool $with
1818
*/
19-
public function __construct(public mixed $with)
19+
public function __construct(public readonly callable|string $with)
2020
{
2121
}
2222
}

src/Symfony/Component/AutoMapper/AutoMapper.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818
final class AutoMapper implements AutoMapperInterface
1919
{
20-
public function __construct(private ?PropertyAccessorInterface $propertyAccessor = null, private ?ContainerInterface $serviceLocator = null)
20+
public function __construct(private readonly ?PropertyAccessorInterface $propertyAccessor = null, private readonly ?ContainerInterface $serviceLocator = null)
2121
{
2222
}
2323

@@ -47,6 +47,9 @@ public function map(object $object, object|string|null $to = null): mixed
4747
}
4848

4949
foreach ($refl->getProperties() as $property) {
50+
if ($property->isStatic() {
51+
continue;
52+
}
5053
$propertyName = $property->getName();
5154
$mapTo = $this->getAttribute($property, MapTo::class)?->to ?? $propertyName;
5255
if (!$toRefl->hasProperty($mapTo)) {
@@ -64,7 +67,7 @@ public function map(object $object, object|string|null $to = null): mixed
6467
$value = $this->call($mapWith, $value, $object);
6568
}
6669

67-
if (is_object($value) && $to = $this->getAttribute(new \ReflectionClass(get_class($value)), MapTo::class)?->to) {
70+
if (is_object($value) && $to = $this->getAttribute(new \ReflectionClass($value), MapTo::class)?->to) {
6871
$value = $this->map($value, $to);
6972
}
7073

@@ -99,7 +102,7 @@ private function call(callable $fn, mixed $value, object $object): mixed
99102

100103
private function getCallable(string|callable|null $fn): ?callable
101104
{
102-
if ($this->serviceLocator && is_string($fn) && $this->serviceLocator->has($fn)) {
105+
if ($this->serviceLocator && is_string($fn)) {
103106
return $this->serviceLocator->get($fn);
104107
}
105108

0 commit comments

Comments
 (0)
0