Valinor/tests/Integration/Mapping/Object
Romain Canon 718d3c1bc2 feat: introduce automatic named constructor resolution
An object may have several ways of being created — in such cases it is
common to use so-called named constructors, also known as static factory
methods. If one or more are found, they can be called during the mapping
to create an instance of the object.

What defines a named constructor is a method that:

1. is public
2. is static
3. returns an instance of the object
4. has one or more arguments

```php
final class Color
{
    /**
     * @param int<0, 255> $red
     * @param int<0, 255> $green
     * @param int<0, 255> $blue
     */
    private function __construct(
        public readonly int $red,
        public readonly int $green,
        public readonly int $blue
    ) {}

    /**
     * @param int<0, 255> $red
     * @param int<0, 255> $green
     * @param int<0, 255> $blue
     */
    public static function fromRgb(
        int $red,
        int $green,
        int $blue,
    ): self {
        return new self($red, $green, $blue);
    }

    /**
     * @param non-empty-string $hex
     */
    public static function fromHex(string $hex): self
    {
        if (strlen($hex) !== 6) {
            throw new DomainException('Must be 6 characters long');
        }

        /** @var int<0, 255> $red */
        $red = hexdec(substr($hex, 0, 2));
        /** @var int<0, 255> $green */
        $green = hexdec(substr($hex, 2, 2));
        /** @var int<0, 255> $blue */
        $blue = hexdec(substr($hex, 4, 2));

        return new self($red, $green, $blue);
    }
}
```
2022-01-25 18:32:28 +01:00
..
ArrayValuesMappingTest.php feat!: wrap node messages in proper class 2022-01-06 14:11:42 +01:00
DateTimeMappingTest.php misc!: allow object builder to yield arguments without source 2022-01-07 13:41:15 +01:00
EnumValuesMappingTest.php feat!: allow mapping to any type 2022-01-02 00:48:01 +01:00
GenericValuesMappingTest.php feat!: allow mapping to any type 2022-01-02 00:48:01 +01:00
IterableValuesMappingTest.php feat!: allow mapping to any type 2022-01-02 00:48:01 +01:00
ListValuesMappingTest.php feat!: wrap node messages in proper class 2022-01-06 14:11:42 +01:00
LocalTypeAliasMappingTest.php feat!: allow mapping to any type 2022-01-02 00:48:01 +01:00
ObjectValuesMappingTest.php misc!: allow object builder to yield arguments without source 2022-01-07 13:41:15 +01:00
ScalarValuesMappingTest.php feat!: wrap node messages in proper class 2022-01-06 14:11:42 +01:00
ShapedArrayValuesMappingTest.php feat!: wrap node messages in proper class 2022-01-06 14:11:42 +01:00
UnionOfObjectsMappingTest.php feat: introduce automatic named constructor resolution 2022-01-25 18:32:28 +01:00
UnionValuesMappingTest.php feat!: allow mapping to any type 2022-01-02 00:48:01 +01:00