public function __construct(string $name, MapInterface $attributes) { if (empty($name) || (string) $attributes->keyType() !== 'string' || (string) $attributes->valueType() !== AttributeInterface::class) { throw new InvalidArgumentException(); } $this->name = $name; $this->content = $attributes; $this->parsingTime = $attributes->reduce(0, function (int $parsingTime, string $name, AttributeInterface $attribute) : int { return $parsingTime += $attribute->parsingTime(); }); }
private function fill(array $default, MapInterface $cells) : array { $line = $cells->reduce($default, function (array $carry, $column, CellInterface $cell) : array { $class = get_class($cell); if ($this->formatters->contains($class)) { $carry[$column] = $this->formatters->get($class)->format($cell); } else { $carry[$column] = (string) $cell; } return $carry; }); return array_values($line); }