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

Array key cannot contain class name #337

Closed
danog opened this issue Feb 3, 2023 · 2 comments · Fixed by #399
Closed

Array key cannot contain class name #337

danog opened this issue Feb 3, 2023 · 2 comments · Fixed by #399

Comments

@danog
Copy link
Contributor

danog commented Feb 3, 2023

<?php

use CuyZ\Valinor\MapperBuilder;

require 'vendor/autoload.php';

class Test {
}

(new MapperBuilder)->mapper()->map('array{Test: string}', ['Test' => 'b']);

Fails with Uncaught CuyZ\Valinor\Mapper\Exception\InvalidMappingTypeSignature: Could not parse the type array{Test: string} that should be mapped: Missing second colon symbol for class constant Test::string.

Quoting the Test key fixes the issue temporarily.

@Brammm
Copy link

Brammm commented May 17, 2023

Ran into this today as well when trying to validate an array shape that contained an enum. Quote the keys as below fixes it:

final class AddContact
{
    public function __construct(
        // other fields
        /**
         * @var array{
         *     "name": string,
         *     "sector": Sector|null,
         *     "email": string|null,
         *     "website": string|null,
         *     "vat_number": VatNumber|null,
         *     "address_line": string|null,
         *     "locality": string|null,
         *     "country": Country,
         * }
         */
        public readonly array $company,
    ) {
    }
}

@romm
Copy link
Member

romm commented Aug 13, 2023

Hey there, thanks for the report! This issue should be fixed with #399 and will be part of the next release. 😉

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

Successfully merging a pull request may close this issue.

3 participants