You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that Valinor may crash when encountering a type syntax it doesn't support yet. This can be an issue as this prevents from using some PHPStan/Psalm features on objects that may be mapped by Valinor.
For example, the following code:
<?phprequire'vendor/autoload.php';
classB {}
classA
{
/** * @phpstan-param ($a is 1 ? B : null) $b * @param B|null $b */publicfunction__construct(
public readonly int$a,
public readonly ?B$b,
) {
}
}
return (new \CuyZ\Valinor\MapperBuilder())
->mapper()
->map(
A::class,
new \CuyZ\Valinor\Mapper\Source\JsonSource('{"a":0,"b":null}')
);
<?php
final class LoginResult
{
public const OK = 'Ok';
public const FAILED = 'Failed';
}
final class LoginResponse
{
public function __construct(
/** @var LoginResult::* */ // <-------------- problem with this annotation with ::*
public readonly string $LoginResult
)
{
}
}
return (new \CuyZ\Valinor\MapperBuilder())
->allowSuperfluousKeys()
->mapper()
->map(
LoginResponse::class,
\CuyZ\Valinor\Mapper\Source\Source::json('{"LoginResult":"Ok"}')
);
The above scenario throws exception AssertionError: assert(!$type instanceof UnresolvableType).
Works correctly when annotated explicitly with: /** @var LoginResult::OK|LoginResult::FAILED */.
I think that the fallback option is not the best as it cannot be guaranteed that the @param annotation works as well.
I was thinking about adding a @valinor-* annotation support that has precedence over all the others, for the following cases: @valinor-var, @valinor-param, @valinor-return, @valinor-extends, @valinor-template, @valinor-type.
It appears that Valinor may crash when encountering a type syntax it doesn't support yet. This can be an issue as this prevents from using some PHPStan/Psalm features on objects that may be mapped by Valinor.
For example, the following code:
leads to this assertion failure:
Should Valinor fallback to the unprefixed
@param
in this case?The text was updated successfully, but these errors were encountered: