Completed
Push — master ( 3090c1...7517cd )
by Adrien
12:19
created

CsvContiguousFilter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 48
rs 10
c 1
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setFilterType() 0 3 1
A setRows() 0 4 1
A readCell() 0 7 2
A filter1() 0 4 1
A filter0() 0 8 4
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader;
4
5
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
6
7
/**  Define a Read Filter class implementing IReadFilter  */
8
class CsvContiguousFilter implements IReadFilter
9
{
10
    private $startRow = 0;
11
12
    private $endRow = 0;
13
14
    private $filterType = 0;
15
16
    /**
17
     * Set the list of rows that we want to read.
18
     *
19
     * @param mixed $startRow
20
     * @param mixed $chunkSize
21
     */
22
    public function setRows($startRow, $chunkSize)
23
    {
24
        $this->startRow = $startRow;
25
        $this->endRow = $startRow + $chunkSize;
26
    }
27
28
    public function setFilterType($type)
29
    {
30
        $this->filterType = $type;
31
    }
32
33
    public function filter1($row)
34
    {
35
        //  Include rows 1-10, followed by 100-110, etc.
36
        return $row % 100 <= 10;
37
    }
38
39
    public function filter0($row)
40
    {
41
        //  Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow
42
        if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) {
43
            return true;
44
        }
45
46
        return false;
47
    }
48
49
    public function readCell($column, $row, $worksheetName = '')
50
    {
51
        if ($this->filterType == 1) {
52
            return $this->filter1($row);
53
        }
54
55
        return $this->filter0($row);
56
    }
57
}
58