phonetworks/pho-compiler

View on GitHub
src/Pho/Compiler/Transcoders/TranscoderFactory.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

/*
 * This file is part of the Pho package.
 *
 * (c) Emre Sokullu <emre@phonetworks.org>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Pho\Compiler\Transcoders;

use Pho\Compiler\Prototypes\PrototypeInterface;
use Pho\Compiler\Prototypes\NodePrototype;
use Pho\Compiler\Prototypes\EdgePrototype;
use Pho\Compiler\Exceptions\UnknownPrototypeException;

class TranscoderFactory
{

    public static function transcode(PrototypeInterface $prototype): TranscoderInterface
    {
        if($prototype instanceof NodePrototype) {
            return new NodeTranscoder($prototype);
        }
        else if($prototype instanceof EdgePrototype) {  
            return new EdgeTranscoder($prototype);
        }
        throw new UnknownPrototypeException();
    }

}