mirror of
https://github.com/danog/Valinor.git
synced 2024-12-11 16:49:51 +01:00
b2e810e3ce
Previously, the method `TreeMapper::map` would allow mapping only to an object. It is now possible to map to any type handled by the library. It is for instance possible to map to an array of objects: ```php $objects = (new \CuyZ\Valinor\MapperBuilder())->mapper()->map( 'array<' . SomeClass::class . '>', [/* … */] ); ``` For simple use-cases, an array shape can be used: ```php $array = (new \CuyZ\Valinor\MapperBuilder())->mapper()->map( 'array{foo: string, bar: int}', [/* … */] ); echo strtolower($array['foo']); echo $array['bar'] * 2; ``` This new feature changes the possible behaviour of the mapper, meaning static analysis tools need help to understand the types correctly. An extension for PHPStan and a plugin for Psalm are now provided and can be included in a project to automatically increase the type coverage.
15 lines
323 B
PHP
15 lines
323 B
PHP
<?php
|
|
|
|
use CuyZ\Valinor\QA\PHPStan\Extension\TreeMapperPHPStanExtension;
|
|
|
|
require_once 'Extension/TreeMapperPHPStanExtension.php';
|
|
|
|
return [
|
|
'services' => [
|
|
[
|
|
'class' => TreeMapperPHPStanExtension::class,
|
|
'tags' => ['phpstan.broker.dynamicMethodReturnTypeExtension']
|
|
]
|
|
],
|
|
];
|