We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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{0: type}
Following works:
<?php namespace My\App; use CuyZ\Valinor\Attribute\StaticMethodConstructor; use CuyZ\Valinor\Mapper\MappingError; use CuyZ\Valinor\MapperBuilder; require_once __DIR__ . '/Valinor/vendor/autoload.php'; class MyArrayWrapper { /** @var array{foo: string, bar: int, baz: bool} */ public array $value; } $mapper = (new MapperBuilder()) ->withCacheDir(__DIR__ . '/cache') ->mapper(); var_dump($mapper->map(MyArrayWrapper::class, ['value' => ['foo' => 'a', 'bar' => '1', 'baz' => 'true']]));
php example.php object(My\App\MyArrayWrapper)#88 (1) { ["value"]=> array(3) { ["foo"]=> string(1) "a" ["bar"]=> int(1) ["baz"]=> bool(true) } }
Doing the same with integer array keys seems to make the tooling choke:
<?php namespace My\App; use CuyZ\Valinor\Attribute\StaticMethodConstructor; use CuyZ\Valinor\Mapper\MappingError; use CuyZ\Valinor\MapperBuilder; require_once __DIR__ . '/Valinor/vendor/autoload.php'; class MyArrayWrapper { /** @var array{0: string, 1: int, 2: bool} */ public array $value; } $mapper = (new MapperBuilder()) ->withCacheDir(__DIR__ . '/cache') ->mapper(); var_dump($mapper->map(MyArrayWrapper::class, ['value' => [0 => 'a', 1 => '1', 2 => 'true']]));
php example.php Fatal error: Uncaught CuyZ\Valinor\Type\Parser\Exception\Stream\WrongTokenType: Wrong token type `CuyZ\Valinor\Type\Parser\Lexer\Token\ColonToken`, it should be an instance of `CuyZ\Valinor\Type\Parser\Lexer\Token\TraversingToken`. in /app/Valinor/src/Type/Parser/Lexer/TokenStream.php:36 Stack trace: #0 /app/Valinor/src/Type/Parser/Lexer/Token/ArrayToken.php(131): CuyZ\Valinor\Type\Parser\Lexer\TokenStream->read() #1 /app/Valinor/src/Type/Parser/Lexer/Token/ArrayToken.php(66): CuyZ\Valinor\Type\Parser\Lexer\Token\ArrayToken->shapedArrayType(Object(CuyZ\Valinor\Type\Parser\Lexer\TokenStream)) #2 /app/Valinor/src/Type/Parser/Lexer/TokenStream.php(39): CuyZ\Valinor\Type\Parser\Lexer\Token\ArrayToken->traverse(Object(CuyZ\Valinor\Type\Parser\Lexer\TokenStream)) #3 /app/Valinor/src/Type/Parser/LexingParser.php(39): CuyZ\Valinor\Type\Parser\Lexer\TokenStream->read() #4 /app/Valinor/src/Definition/Repository/Reflection/ReflectionPropertyDefinitionBuilder.php(132): CuyZ\Valinor\Type\Parser\LexingParser->parse('array{0: string...') #5 /app/Valinor/src/Definition/Repository/Reflection/ReflectionPropertyDefinitionBuilder.php(110): CuyZ\Valinor\Definition\Repository\Reflection\ReflectionPropertyDefinitionBuilder->parseType('array{0: string...', Object(ReflectionProperty), Object(CuyZ\Valinor\Type\Parser\LexingParser)) #6 /app/Valinor/src/Definition/Repository/Reflection/ReflectionPropertyDefinitionBuilder.php(70): CuyZ\Valinor\Definition\Repository\Reflection\ReflectionPropertyDefinitionBuilder->typeFromDocBlock(Object(CuyZ\Valinor\Definition\ClassSignature), Object(ReflectionProperty)) #7 /app/Valinor/src/Definition/Repository/Reflection/ReflectionPropertyDefinitionBuilder.php(43): CuyZ\Valinor\Definition\Repository\Reflection\ReflectionPropertyDefinitionBuilder->resolveType(Object(CuyZ\Valinor\Definition\ClassSignature), Object(ReflectionProperty)) #8 /app/Valinor/src/Definition/Repository/Reflection/ReflectionClassDefinitionRepository.php(41): CuyZ\Valinor\Definition\Repository\Reflection\ReflectionPropertyDefinitionBuilder->for(Object(CuyZ\Valinor\Definition\ClassSignature), Object(ReflectionProperty)) #9 [internal function]: CuyZ\Valinor\Definition\Repository\Reflection\ReflectionClassDefinitionRepository->CuyZ\Valinor\Definition\Repository\Reflection\{closure}(Object(ReflectionProperty)) #10 /app/Valinor/src/Definition/Repository/Reflection/ReflectionClassDefinitionRepository.php(42): array_map(Object(Closure), Array) #11 /app/Valinor/src/Definition/Repository/Cache/CacheClassDefinitionRepository.php(36): CuyZ\Valinor\Definition\Repository\Reflection\ReflectionClassDefinitionRepository->for(Object(CuyZ\Valinor\Definition\ClassSignature)) #12 /app/Valinor/src/Mapper/Tree/Builder/ClassNodeBuilder.php(35): CuyZ\Valinor\Definition\Repository\Cache\CacheClassDefinitionRepository->for(Object(CuyZ\Valinor\Definition\ClassSignature)) #13 /app/Valinor/src/Mapper/Tree/Builder/CasterNodeBuilder.php(35): CuyZ\Valinor\Mapper\Tree\Builder\ClassNodeBuilder->build(Object(CuyZ\Valinor\Mapper\Tree\Shell), Object(CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder)) #14 /app/Valinor/src/Mapper/Tree/Builder/VisitorNodeBuilder.php(28): CuyZ\Valinor\Mapper\Tree\Builder\CasterNodeBuilder->build(Object(CuyZ\Valinor\Mapper\Tree\Shell), Object(CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder)) #15 /app/Valinor/src/Mapper/Tree/Builder/ValueAlteringNodeBuilder.php(31): CuyZ\Valinor\Mapper\Tree\Builder\VisitorNodeBuilder->build(Object(CuyZ\Valinor\Mapper\Tree\Shell), Object(CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder)) #16 /app/Valinor/src/Mapper/Tree/Builder/ShellVisitorNodeBuilder.php(30): CuyZ\Valinor\Mapper\Tree\Builder\ValueAlteringNodeBuilder->build(Object(CuyZ\Valinor\Mapper\Tree\Shell), Object(CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder)) #17 /app/Valinor/src/Mapper/Tree/Builder/ErrorCatcherNodeBuilder.php(23): CuyZ\Valinor\Mapper\Tree\Builder\ShellVisitorNodeBuilder->build(Object(CuyZ\Valinor\Mapper\Tree\Shell), Object(CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder)) #18 /app/Valinor/src/Mapper/Tree/Builder/RootNodeBuilder.php(21): CuyZ\Valinor\Mapper\Tree\Builder\ErrorCatcherNodeBuilder->build(Object(CuyZ\Valinor\Mapper\Tree\Shell), Object(CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder)) #19 /app/Valinor/src/Mapper/TreeMapperContainer.php(57): CuyZ\Valinor\Mapper\Tree\Builder\RootNodeBuilder->build(Object(CuyZ\Valinor\Mapper\Tree\Shell)) #20 /app/Valinor/src/Mapper/TreeMapperContainer.php(31): CuyZ\Valinor\Mapper\TreeMapperContainer->node('My\\App\\MyArrayW...', Array) #21 /app/example.php(22): CuyZ\Valinor\Mapper\TreeMapperContainer->map('My\\App\\MyArrayW...', Array) #22 {main} thrown in /app/Valinor/src/Type/Parser/Lexer/TokenStream.php on line 36
The text was updated successfully, but these errors were encountered:
phpstan/phpstan
vimeo/psalm
@Ocramius thanks for digging such cases 😛
Should be ok by now on your side, can you confirm?
Sorry, something went wrong.
Seems to work as expected now, thanks @romm!
Found another issue, but will report it separately.
Money\Money::__construct($currency)
int|string
Money\Currency
No branches or pull requests
Following works:
Doing the same with integer array keys seems to make the tooling choke:
The text was updated successfully, but these errors were encountered: