martin-helmich/typo3-typoscript-parser

View on GitHub
src/Tokenizer/LineGrouper.php

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
<?php declare(strict_types=1);

namespace Helmich\TypoScriptParser\Tokenizer;

/**
 * Class LineGrouper
 *
 * @package    Helmich\TypoScriptParser
 * @subpackage Tokenizer
 */
class LineGrouper
{
    /** @var TokenInterface[][] */
    private array $tokensByLine = [];

    /**
     * @param TokenInterface[] $tokens
     */
    public function __construct(array $tokens)
    {
        foreach ($tokens as $token) {
            if (!array_key_exists($token->getLine(), $this->tokensByLine)) {
                $this->tokensByLine[$token->getLine()] = [];
            }
            $this->tokensByLine[$token->getLine()][] = $token;
        }
    }

    /**
     * @return TokenInterface[][]
     */
    public function getLines(): array
    {
        return $this->tokensByLine;
    }
}