Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
1 / 1
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3declare(strict_types=1);
4
5/** @license For full copyright and license information, please see the LICENSE.md file. */
6
7namespace App\Core\DataExchange\Infrastructure\Reader;
8
9defined('AMMONLY_APP') || exit('Direct script access is forbidden.');
10
11use Generator;
12
13/**
14 * Contract for memory-efficient streaming readers of tabular file formats (CSV, XLSX, TXT).
15 *
16 * @package App\Core\DataExchange\Infrastructure\Reader
17 */
18interface TabularStreamReaderInterface
19{
20    /**
21     * Determines whether the reader supports the specified file type.
22     *
23     * @param string $filePath Path to candidate file.
24     * @return bool True if supported.
25     */
26    public function supports(string $filePath): bool;
27
28    /**
29     * Extracts column header names from the first data row.
30     *
31     * @param string $filePath Path to source file.
32     * @return list<string> Ordered list of header column names.
33     */
34    public function getHeaders(string $filePath): array;
35
36    /**
37     * Retrieves up to $limit preview rows mapped to header keys.
38     *
39     * @param string $filePath Path to source file.
40     * @param int    $limit    Maximum sample rows to retrieve (default 3).
41     * @return list<array<string, string>> Sample data rows.
42     */
43    public function getSampleRows(string $filePath, int $limit = 3): array;
44
45    /**
46     * Iterates through data rows one-by-one via PHP Generator.
47     *
48     * @param string $filePath Path to source file.
49     * @return Generator<int, array<string, string>> Yields 1-indexed row number and associative row data.
50     */
51    public function iterateRows(string $filePath): Generator;
52}