klitsche/ffigen

View on GitHub
src/Adapter/PHPCParser/Compiler/BuiltinTypeTranslator.php

Summary

Maintainability
A
0 mins
Test Coverage
C
77%
<?php

declare(strict_types=1);

namespace Klitsche\FFIGen\Adapter\PHPCParser\Compiler;

use Klitsche\FFIGen\Types\Builtin;
use Klitsche\FFIGen\Types\Type;
use PHPCParser\Node\Type\BuiltinType;
use PHPCParser\NodeAbstract;

class BuiltinTypeTranslator extends AbstractTranslator
{
    public function setCompiler(CompilerInterface $compiler): void
    {
        $this->compiler = $compiler;
    }

    public function matches(NodeAbstract $node): bool
    {
        return $node instanceof BuiltinType;
    }

    public function compile(NodeAbstract $node): Type
    {
        if (Builtin::isMappable($node->name)) {
            return new Builtin($node->name);
        }

        var_dump($node);
        throw new \LogicException(sprintf('Unsupported builtin type: %s, %s', get_class($node), $node->name));
    }
}