railt/parser

View on GitHub
src/Parser/Ast/Leaf.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
/**
 * This file is part of Railt package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
declare(strict_types=1);

namespace Railt\Component\Parser\Ast;

use Railt\Component\Lexer\TokenInterface;

/**
 * Class Leaf
 */
class Leaf extends Node implements LeafInterface
{
    /**
     * @var array
     */
    private $value;

    /**
     * Leaf constructor.
     *
     * @param TokenInterface $token
     */
    public function __construct(TokenInterface $token)
    {
        parent::__construct($token->getName(), $token->getOffset());

        $this->value = $token->getGroups();
    }

    /**
     * @param int $group
     * @return null|string
     */
    public function getValue(int $group = 0): ?string
    {
        return $this->value[$group] ?? null;
    }

    /**
     * @return iterable|string[]
     */
    public function getValues(): iterable
    {
        return $this->value;
    }
}