-
Notifications
You must be signed in to change notification settings - Fork 59
[Bug] Incorrect generic extends of RuleFactoryInterface #595
Copy link
Copy link
Open
Labels
BugSomething isn't workingSomething isn't working
Description
What are you really trying to do?
There is no correct way to use generic for your marshall-types.
Describe the bug
RuleFactoryInterface is not a generic interface and does not give you the ability to specify your own type:
/**
* @extends TypeInterface<mixed>
*/
interface RuleFactoryInterface extends TypeInterface {}Therefore, when using this interface together with an abstract Type (like UuidType) we get this error from phpstan
Class Temporal\Internal\Marshaller\Type\Type specifies template type TMarshalType of interface Temporal\Internal\Marshaller\Type\TypeInterface as int<0, max> but it's already specified as mixed.
🪪 generics.interfaceConflict
Minimal Reproduction
/**
* @extends Type<non-negative-int>
*/
final class SomeType extends Type implements DetectableTypeInterface, RuleFactoryInterface
{
#[Override]
public function parse(mixed $value, mixed $current): Some
{
return Some::fromInt($value);
}
#[Override]
public function serialize(mixed $value): int
{
return $value->toInt();
}
#[Override]
public static function match(ReflectionNamedType $type): bool
{
return !$type->isBuiltin() && $type->getName() === Some::class;
}
#[Override]
public static function makeRule(ReflectionProperty $property): ?MarshallingRule
{
$type = $property->getType();
if (!$type instanceof ReflectionNamedType || !self::match($type)) {
return null;
}
if ($type->allowsNull()) {
return new MarshallingRule(
name: $property->getName(),
type: NullableType::class,
of: new MarshallingRule(
type: self::class,
of: $type->getName(),
),
);
}
return new MarshallingRule(
name: $property->getName(),
type: self::class,
of: $type->getName(),
);
}
}Environment/Versions
- Temporal SDK Version: 2.13.4
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugSomething isn't workingSomething isn't working