railt/graphql

View on GitHub
src/Compiler/Command/Define/DefineInterfaceTypeDefinitionCommand.php

Summary

Maintainability
A
2 hrs
Test Coverage
<?php

declare(strict_types=1);

namespace Railt\SDL\Compiler\Command\Define;

use Railt\SDL\Compiler\Command\Build\BuildInterfaceTypeDefinitionCommand;
use Railt\SDL\Compiler\Command\DefineCommand;
use Railt\SDL\Node\Statement\Definition\InterfaceTypeDefinitionNode;
use Railt\TypeSystem\Definition\Type\InterfaceType;

/**
 * @template-extends DefineCommand<InterfaceTypeDefinitionNode>
 *
 * @internal This is an internal library class, please do not use it in your code.
 * @psalm-internal Railt\SDL\Compiler\Command
 */
final class DefineInterfaceTypeDefinitionCommand extends DefineCommand
{
    public function exec(): void
    {
        $type = new InterfaceType($this->stmt->name->value);

        if ($this->stmt->description->value !== null) {
            $type->setDescription($this->stmt->description->value->value);
        }

        $this->ctx->addType($type, $this->stmt->name);

        $this->ctx->push(new BuildInterfaceTypeDefinitionCommand(
            ctx: $this->ctx,
            node: $this->stmt,
            definition: $type,
        ));
    }
}