mirror of
https://github.com/danog/Valinor.git
synced 2024-11-26 20:24:40 +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.
39 lines
1.2 KiB
PHP
39 lines
1.2 KiB
PHP
<?php
|
|
|
|
$finder = PhpCsFixer\Finder::create()->in([
|
|
'./src',
|
|
'./tests',
|
|
'./qa',
|
|
]);
|
|
|
|
if (PHP_VERSION_ID < 8_00_00) {
|
|
$finder = $finder
|
|
->notPath('Fixture/Attribute/AttributeWithArguments.php')
|
|
->notPath('Fixture/Object/ObjectWithAttributes.php')
|
|
->notPath('Fixture/Object/ObjectWithPropertyWithNativeUnionType.php')
|
|
->notPath('Integration/Mapping/Fixture/NativeUnionValues.php');
|
|
}
|
|
|
|
if (PHP_VERSION_ID < 8_01_00) {
|
|
$finder = $finder->notPath('Fixture/Enum/PureEnum.php');
|
|
$finder = $finder->notPath('Fixture/Enum/BackedStringEnum.php');
|
|
$finder = $finder->notPath('Fixture/Enum/BackedIntegerEnum.php');
|
|
$finder = $finder->notPath('Fixture/Object/ObjectWithPropertyWithNativeIntersectionType.php');
|
|
$finder = $finder->notPath('Integration/Mapping/Fixture/ReadonlyValues.php');
|
|
}
|
|
|
|
return (new PhpCsFixer\Config())
|
|
->setFinder($finder)
|
|
->setCacheFile('var/cache/.php_cs.cache')
|
|
->setRules([
|
|
'@PSR1' => true,
|
|
'@PSR12' => true,
|
|
'no_unused_imports' => true,
|
|
'no_extra_blank_lines' => true,
|
|
'no_empty_phpdoc' => true,
|
|
'no_superfluous_phpdoc_tags' => [
|
|
'allow_mixed' => true,
|
|
'remove_inheritdoc' => true
|
|
],
|
|
]);
|