Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Attribute/ObjectType/Slots.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function getDefinition(ObjectListInterface $case, \Reflector $r): mixed
$parametersFrom = false === $this->bindPromotedProperties ? $reflectionMethod : ($reflectionMethod->getDeclaringClass()->getConstructor() ?? throw new \LogicException('A constructor must be defined to use `bindPromotedProperties`'));
foreach ($parametersFrom->getParameters() as $rParam) {
$paramType = $rParam->getType();
if ($paramType instanceof \ReflectionNamedType) {
if ($paramType instanceof \ReflectionNamedType || $paramType instanceof \ReflectionUnionType) {
// @todo use the type @ $paramType->getName()
$args = ['name' => $rParam->getName()];
// Default should only be set if there is a default.
Expand Down
2 changes: 1 addition & 1 deletion src/PintoMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @param array<class-string<ObjectListInterface>> $enumClasses
* @param array<
* class-string,
* array{class-string<\Pinto\List\ObjectListInterface>, string}
* array{class-string<ObjectListInterface>, string}
* > $enums
* @param array<class-string, mixed> $definitions
* @param array<class-string, string> $buildInvokers
Expand Down
4 changes: 3 additions & 1 deletion tests/PintoSlotsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@ public function testPintoObjectSlotsBindPromotedPublic(): void
new Slots\Slot(name: 'aPublic', fillValueFromThemeObjectClassPropertyWhenEmpty: 'aPublic'),
new Slots\Slot(name: 'aPublicAndSetInInvoker', fillValueFromThemeObjectClassPropertyWhenEmpty: 'aPublicAndSetInInvoker'),
new Slots\Slot(name: 'aPrivate'),
new Slots\Slot(name: 'unionType', fillValueFromThemeObjectClassPropertyWhenEmpty: 'unionType'),
]), $slotsDefinition->slots);

$object = new PintoObjectSlotsBindPromotedPublic('the public', 'public but also overridden in invoker', 'the private');
$object = new PintoObjectSlotsBindPromotedPublic('the public', 'public but also overridden in invoker', 'the private', 42.0);
$build = $object();
static::assertInstanceOf(Slots\Build::class, $build);
static::assertEquals('the public', $build->pintoGet('aPublic'));
static::assertEquals('public value set in invoker', $build->pintoGet('aPublicAndSetInInvoker'));
static::assertEquals('private value set in invoker', $build->pintoGet('aPrivate'));
static::assertEquals(42.0, $build->pintoGet('unionType'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function __construct(
public readonly string $aPublicAndSetInInvoker,
// @phpstan-ignore-next-line
private readonly string $aPrivate,
public readonly string|int|float|null $unionType,
) {
}

Expand All @@ -32,7 +33,8 @@ public function __invoke(): mixed
return $this->pintoBuild(function (Slots\Build $build): Slots\Build {
return $build
->set('aPublicAndSetInInvoker', 'public value set in invoker')
->set('aPrivate', 'private value set in invoker');
->set('aPrivate', 'private value set in invoker')
->set('unionType', 42.0);
});
}

Expand All @@ -48,6 +50,7 @@ enums: [
new Slots\Slot(name: 'aPublic', defaultValue: new NoDefaultValue(), fillValueFromThemeObjectClassPropertyWhenEmpty: 'aPublic'),
new Slots\Slot(name: 'aPublicAndSetInInvoker', defaultValue: new NoDefaultValue(), fillValueFromThemeObjectClassPropertyWhenEmpty: 'aPublicAndSetInInvoker'),
new Slots\Slot(name: 'aPrivate', defaultValue: new NoDefaultValue(), fillValueFromThemeObjectClassPropertyWhenEmpty: null),
new Slots\Slot(name: 'unionType', defaultValue: new NoDefaultValue(), fillValueFromThemeObjectClassPropertyWhenEmpty: null),
])),
],
buildInvokers: [
Expand Down
Loading