Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing DateTimeZone is formatted as ? #556

Open
dejagersh opened this issue Sep 2, 2024 · 0 comments
Open

Missing DateTimeZone is formatted as ? #556

dejagersh opened this issue Sep 2, 2024 · 0 comments

Comments

@dejagersh
Copy link

dejagersh commented Sep 2, 2024

Hi there, not sure if this is intended, but consider this minimal example:

<?php

declare(strict_types=1);

use CuyZ\Valinor\Mapper\MappingError;
use CuyZ\Valinor\Mapper\Tree\Message\Messages;
use CuyZ\Valinor\MapperBuilder;

require_once __DIR__ . '/vendor/autoload.php';

class City
{
    public function __construct(public readonly DateTimeZone $timeZone)
    {
    }
}

try {
    $city = (new MapperBuilder())->mapper()->map(
        City::class,
        [] // Missing `timeZone`
    );
} catch (MappingError $e) {
    $messages = Messages::flattenFromNode($e->node())->toArray();

    var_dump($messages[0]->toString());
}

Output:

Cannot be empty and must be filled with a value matching type `?`

This seems to be the responsible method, and the red block is where it falls into.

image

I'm not so familiar of course with this codebase, but can't it somehow use getType() here? When I replace that ? with $type->toString() it shows up nicely as DateTimeZone.

Cannot be empty and must be filled with a value matching type `DateTimeZone`.

I am trying to send these errors to our error reporting system, and looking to get something more meaningful than ? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant