TabularDataReader
last analyzed

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 81
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
count() 0 1 ?
getIterator() 0 1 ?
getHeader() 0 1 ?
getRecords() 0 1 ?
fetchOne() 0 1 ?
fetchColumn() 0 1 ?
fetchPairs() 0 1 ?
1
<?php
2
3
/**
4
 * League.Csv (https://csv.thephpleague.com)
5
 *
6
 * (c) Ignace Nyamagana Butera <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace League\Csv;
15
16
use Countable;
17
use Iterator;
18
use IteratorAggregate;
19
20
/**
21
 * Represents a Tabular data.
22
 */
23
interface TabularDataReader extends Countable, IteratorAggregate
24
{
25
    /**
26
     * Returns the number of records contained in the tabular data structure
27
     * excluding the header record.
28
     */
29
    public function count(): int;
30
31
    /**
32
     * Returns the tabular data records as an iterator object.
33
     *
34
     * Each record is represented as a simple array containing strings or null values.
35
     *
36
     * If the CSV document has a header record then each record is combined
37
     * to the header record and the header record is removed from the iterator.
38
     *
39
     * If the CSV document is inconsistent. Missing record fields are
40
     * filled with null values while extra record fields are strip from
41
     * the returned object.
42
     */
43
    public function getIterator(): Iterator;
44
45
    /**
46
     * Returns the header associated with the tabular data.
47
     *
48
     * The header must contains unique string or is an empty array
49
     * if no header was specified.
50
     *
51
     * @return string[]
52
     */
53
    public function getHeader(): array;
54
55
    /**
56
     * Returns the tabular data records as an iterator object.
57
     *
58
     * Each record is represented as a simple array containing strings or null values.
59
     *
60
     * If the tabular data has a header record then each record is combined
61
     * to the header record and the header record is removed from the iterator.
62
     *
63
     * If the tabular data is inconsistent. Missing record fields are
64
     * filled with null values while extra record fields are strip from
65
     * the returned object.
66
     *
67
     * @param string[] $header an optional header to use instead of the CSV document header
68
     */
69
    public function getRecords(array $header = []): Iterator;
70
71
    /**
72
     * Returns the nth record from the tabular data.
73
     *
74
     * By default if no index is provided the first record of the tabular data is returned
75
     *
76
     * @param int $nth_record the tabular data record offset
77
     *
78
     * @throws Exception if argument is lesser than 0
79
     */
80
    public function fetchOne(int $nth_record = 0): array;
81
82
    /**
83
     * Returns a single column from the next record of the tabular data.
84
     *
85
     * By default if no value is supplied the first column is fetch
86
     *
87
     * @param string|int $index CSV column index
88
     */
89
    public function fetchColumn($index = 0): Iterator;
90
91
    /**
92
     * Returns the next key-value pairs from the tabular data (first
93
     * column is the key, second column is the value).
94
     *
95
     * By default if no column index is provided:
96
     * - the first column is used to provide the keys
97
     * - the second column is used to provide the value
98
     *
99
     * @param string|int $offset_index The column index to serve as offset
100
     * @param string|int $value_index  The column index to serve as value
101
     */
102
    public function fetchPairs($offset_index = 0, $value_index = 1): Iterator;
103
}
104