spaghettisolutions/xlsx-parser

View on GitHub
src/XLSXParser/AbstractXMLDictionary.php

Summary

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

namespace Spaghetti\XLSXParser;

use function implode;
use function is_array;
use function trim;

/**
 * @internal
 */
abstract class AbstractXMLDictionary extends AbstractXMLResource
{
    protected bool $valid = true;
    protected array $values = [];

    public function get(int $index): mixed
    {
        while ($this->valid && !isset($this->values[$index])) {
            $this->readNext();
        }

        if (is_array(value: $this->values[$index])) {
            return trim(string: implode(separator: ' ', array: $this->values[$index]));
        }

        return $this->values[$index];
    }

    abstract protected function readNext();
}