Skip to content

Commit

Permalink
#68 rename configuration property with snake case and attribute with …
Browse files Browse the repository at this point in the history
…camel case
  • Loading branch information
mike4git committed Apr 2, 2024
1 parent 27887e3 commit b3ac36d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/DependencyInjection/NeustaConverterExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function loadInternal(array $mergedConfig, ContainerBuilder $container):
private function registerConverterConfiguration(string $id, array $config, ContainerBuilder $container): void
{
foreach ($config['properties'] ?? [] as $targetProperty => $sourceConfig) {
$skip_null = false;
$skipNull = false;
if (str_ends_with($targetProperty, '?')) {
$skip_null = true;
$skipNull = true;
$targetProperty = substr($targetProperty, 0, -1);
}
$config['populators'][] = $propertyPopulatorId = "{$id}.populator.{$targetProperty}";
Expand All @@ -55,7 +55,7 @@ private function registerConverterConfiguration(string $id, array $config, Conta
'$defaultValue' => $sourceConfig['default'] ?? null,
'$mapper' => null,
'$accessor' => new Reference('property_accessor'),
'$skip_null' => $sourceConfig['skip_null'] || $skip_null,
'$skipNull' => $sourceConfig['skip_null'] || $skipNull,
]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Populator/PropertyMappingPopulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(
private mixed $defaultValue = null,
?\Closure $mapper = null,
?PropertyAccessorInterface $accessor = null,
private bool $skip_null = false,
private bool $skipNull = false,
) {
$this->mapper = $mapper ?? static fn ($v) => $v;
$this->accessor = $accessor ?? PropertyAccess::createPropertyAccessor();
Expand All @@ -45,7 +45,7 @@ public function populate(object $target, object $source, ?object $ctx = null): v
try {
$value = $this->accessor->getValue($source, $this->sourceProperty) ?? $this->defaultValue;

if (!$this->skip_null || (null !== $value)) {
if (!$this->skipNull || (null !== $value)) {
$this->accessor->setValue($target, $this->targetProperty, ($this->mapper)($value, $ctx));
}
} catch (\Throwable $exception) {
Expand Down
2 changes: 1 addition & 1 deletion tests/DependencyInjection/NeustaConverterExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function test_with_mapped_properties(): void
self::assertIsReference('property_accessor', $fullNamePopulator->getArgument('$accessor'));
self::assertSame('fullName', $fullNamePopulator->getArgument('$targetProperty'));
self::assertSame('fullName', $fullNamePopulator->getArgument('$sourceProperty'));
self::assertTrue($fullNamePopulator->getArgument('$skip_null'));
self::assertTrue($fullNamePopulator->getArgument('$skipNull'));

// ageInYears property populator
$this->assertContainerBuilderHasService('foobar.populator.ageInYears', PropertyMappingPopulator::class);
Expand Down

0 comments on commit b3ac36d

Please sign in to comment.