spaghettisolutions/xlsx-parser

View on GitHub
src/XLSXParser/Row.php

Summary

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

namespace Spaghetti\XLSXParser;

use function count;

/**
 * @internal
 */
final class Row
{
    private array $values = [];

    public function addValue(int $columnIndex, mixed $value): void
    {
        if ('' !== $value) {
            $this->values[$columnIndex] = $value;
        }
    }

    public function getData(): array
    {
        $data = [];

        foreach ($this->values as $columnIndex => $value) {
            while (count(value: $data) < $columnIndex) {
                $data[] = '';
            }

            $data[] = $value;
        }

        return $data;
    }
}