flix-tech/avro-serde-php

View on GitHub
src/Objects/Schema/UnionType.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php

declare(strict_types=1);

namespace FlixTech\AvroSerializer\Objects\Schema;

use FlixTech\AvroSerializer\Objects\Schema;

class UnionType extends Schema
{
    /**
     * @var array<Schema>
     */
    private $types;

    public function __construct(Schema $type, Schema ...$types)
    {
        \array_unshift($types, $type);
        $this->types = $types;
    }

    /**
     * @return array<mixed>
     */
    public function serialize(): array
    {
        return \array_map(function (Schema $schema) {
            return $schema->serialize();
        }, $this->types);
    }
}